alexjercan/bugnet huggingface dataset:
Problem p01606 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> ans(2 * (N + W), 0);
  ans[0] = W;
  for (int i = 1; i <= W / 2; ++i) {
    ++ans[i + 1];
  }
  for (int i = W / 2 + 1; i < W; ++i) {
    for (int j = 3; j * i <= N; ++j) {
      ++ans[j * i - W + 1];
      --ans[j * i - W + 1 + W - i];
    }
  }
  for (int i = 1; i <= N - W + 2; ++i) {
    ans[i] += ans[i - 1];
  }
  cout << ans[1];
  for (int i = 2; i <= N - W + 1; ++i)
    cout << " " << ans[i];
  cout << endl;
  return 0;
}


Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> ans(N + W, 0);
  ans[0] = W;
  for (int i = 1; i <= W / 2; ++i) {
    ++ans[i + 1];
  }
  for (int i = W / 2 + 1; i < W; ++i) {
    for (int j = 3; j * i <= N; ++j) {
      ++ans[j * i - W + 1];
      --ans[j * i - W + 1 + W - i];
    }
  }
  for (int i = 1; i <= N - W + 2; ++i) {
    ans[i] += ans[i - 1];
  }
  cout << ans[1];
  for (int i = 2; i <= N - W + 1; ++i)
    cout << " " << ans[i];
  cout << endl;
  return 0;
}
Problem p01606 (C++) — buggy submission, verdict: Runtime Error

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> ans(N + 2, 0);
  ans[0] = W;
  for (int i = 1; i <= W / 2; ++i) {
    ++ans[i + 1];
  }
  for (int i = W / 2 + 1; i < W; ++i) {
    for (int j = 3; j * i <= N; ++j) {
      ++ans[j * i - W + 1];
      --ans[j * i - W + 1 + W - i];
    }
  }
  for (int i = 1; i <= N - W + 2; ++i) {
    ans[i] += ans[i - 1];
  }
  cout << ans[1];
  for (int i = 2; i <= N - W + 1; ++i)
    cout << " " << ans[i];
  cout << endl;
  return 0;
}


Error: 0

Fixed submission:

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> ans(N + 1, 0);
  ans[0] = W;
  for (int i = 1; i <= W / 2; ++i) {
    ++ans[i + 1];
  }
  for (int i = W / 2 + 1; i < W; ++i) {
    for (int j = 3; j * i <= N; ++j) {
      ++ans[j * i - W + 1];
      --ans[j * i - W + 1 + W - i];
    }
  }
  for (int i = 1; i <= N - W + 2; ++i) {
    ans[i] += ans[i - 1];
  }
  cout << ans[1];
  for (int i = 2; i <= N - W + 1; ++i)
    cout << " " << ans[i];
  cout << endl;
  return 0;
}
Problem p01606 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

const int MAXN = 100005;
int N, W;
int num[MAXN];
int ans;
vector<int> d[MAXN];

void add(int v, int end) {
  for (int j = 0; j < d[v].size(); ++j) {
    int i = d[v][j];
    ++num[i];
    if (i < end && num[i] == 2)
      ++ans;
  }
}

void subtract(int v, int end) {
  for (int j = 0; j < d[v].size(); ++j) {
    int i = d[v][j];
    --num[i];
    if (i < end && num[i] == 1)
      --ans;
  }
}

int main() {
  for (int i = 1; i < MAXN; ++i) {
    for (int j = i; j < MAXN; j += i) {
      d[j].push_back(i);
    }
  }

  while (cin >> N >> W) {
    fill(num, num + MAXN, 0);
    ans = W;
    for (int i = 1; i < W; ++i)
      add(i, 1);
    for (int i = W; i <= N; ++i) {
      add(i, i - W + 1);
      if (i != W)
        cout << " ";
      cout << ans;
      subtract(i - W + 1, i - W + 1);
      if (num[i - W + 1] >= 2) {
        ++ans;
      }
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

const int MAXN = 100005;
int N, W;
int num[MAXN];
int ans;

void add(int v, int end) {
  for (int i = 1; i * 2 <= v; ++i) {
    if (v % i == 0) {
      ++num[i];
      if (i < end && num[i] == 2)
        ++ans;
    }
  }
  if (v != 1) {
    ++num[v];
    if (v < end && num[v] == 2)
      ++ans;
  }
}

void subtract(int v, int end) {
  for (int i = 1; i * 2 <= v; ++i) {
    if (v % i == 0) {
      --num[i];
      if (i < end && num[i] == 1)
        --ans;
    }
  }
  if (v != 1) {
    --num[v];
    if (v < end && num[v] == 1)
      --ans;
  }
}

int main() {
  while (cin >> N >> W) {
    fill(num, num + MAXN, 0);
    ans = W;
    for (int i = 1; i < W; ++i)
      add(i, 1);
    for (int i = W; i <= N; ++i) {
      add(i, i - W + 1);
      if (i != W)
        cout << " ";
      cout << ans;
      subtract(i - W + 1, i - W + 1);
      if (num[i - W + 1] >= 2) {
        ++ans;
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p01620 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int Decoding(char c, int key) {

  int num;

  if (c >= 'A' && c <= 'Z') {
    num = c - 65;
  } else {
    num = c - 71;
  }

  num = (num + 51 * key) % 52;

  return num;
}
int main() {

  char list[52];
  string str;
  int n;
  int key[100];

  for (int i = 0; i + 65 <= 90; i++)
    list[i] = i + 65;
  for (int j = 0; j + 97 <= 122; j++)
    list[j + 26] = j + 97;

  while (1) {

    cin >> n;
    if (n == 0)
      break;

    for (int i = 0; i < n; i++)
      cin >> key[i];

    cin >> str;

    for (int i = 0; i < (int)str.size(); i++) {
      cout << list[Decoding(str[i], key[i % n])];
    }

    cout << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int Decoding(char c, int key) {

  int num;

  if (c >= 'A' && c <= 'Z') {
    num = c - 65;
  } else {
    num = c - 71;
  }

  num = (num + 51 * key) % 52;

  return num;
}
int main() {

  char list[52];
  string str;
  int n;
  int key[52];

  for (int i = 0; i + 65 <= 90; i++)
    list[i] = i + 65;
  for (int j = 0; j + 97 <= 122; j++)
    list[j + 26] = j + 97;

  while (1) {

    cin >> n;
    if (n == 0)
      break;

    for (int i = 0; i < n; i++)
      cin >> key[i];

    cin >> str;

    for (int i = 0; i < str.size(); i++) {
      cout << list[Decoding(str[i], key[i % n])];
    }

    cout << endl;
  }

  return 0;
}
Problem p01620 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define INF 1000000

using namespace std;
typedef long long ll;

char back(char a, int bnum) {
  int lest;
  if (bnum > 26) {
    bnum -= 26;
    if ('a' <= a && a <= 'z') {
      a = a + ('A' - 'a');
    } else if ('A' <= a && a <= 'Z') {
      a = a + ('a' - 'A');
    }
  }
  if ('a' <= a && a <= 'z') { // こもじ
    if (a - bnum >= 'a') {
      return a - bnum;
    } else {
      lest = (a - 'a' + 1) - bnum;
      return 'Z' + lest;
    }
  } else if ('A' <= a && a <= 'Z') { // おおもじ
    if (a - bnum >= 'A') {
      return a - bnum;
    } else {
      lest = (a - 'A' + 1) - bnum;
      return 'z' + lest;
    }
  }
  return '+';
}

int main() {
  while (1) {
    int n, k[101], key[101];
    cin >> n;
    if (n == 0)
      break;

    string s;
    for (int i = 0; i < n; i++) {
      cin >> k[i];
    }
    cin >> s;

    int num = 0;
    for (int i = 0; i < 101; i++) {
      key[i] = k[num % (n)];
      num++;
    }
    for (int i = 0; i < s.size(); i++) {
      s[i] = back(s[i], key[i]);
    }
    cout << s << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define INF 1000000

using namespace std;
typedef long long ll;

char back(char a, int bnum) {
  int lest;
  if ('a' <= a && a <= 'z') { // こもじ
    if (a - bnum >= 'a') {
      return a - bnum;
    } else {
      lest = (a - 'a' + 1) - bnum;
      return 'Z' + lest;
    }
  } else if ('A' <= a && a <= 'Z') { // おおもじ
    if (a - bnum >= 'A') {
      return a - bnum;
    } else {
      lest = (a - 'A' + 1) - bnum;
      return 'z' + lest;
    }
  }
}

int main() {
  while (1) {
    int len;
    int n, k[53], key[101];
    cin >> n;
    if (n == 0)
      break;

    string s;
    for (int i = 0; i < n; i++) {
      cin >> k[i];
    }
    cin >> s;

    int num = 0;
    for (int i = 0; i < 101; i++) {
      key[i] = k[num % (n)];
      num++;
    }
    for (int i = 0; i < s.size(); i++) {
      s[i] = back(s[i], key[i]);
    }
    cout << s << endl;
  }
  return 0;
}
Problem p01620 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
int main() {
  char data[53];
  for (int i = 0; i < 26; i++) {
    data[i] = 'A' + i;
    data[i + 26] = 'a' + i;
  }
  int n, k;
  string s;
  while (cin >> n, n) {
    int k[100];
    for (int i = 0; i < n; i++)
      cin >> k[i];
    cin >> s;
    int a[100];
    for (int i = 0; i < s.size(); i++) {
      if (s[i] >= 'a')
        a[i] = 26 + (s[i] - 'a');
      else
        a[i] = s[i] - 'A';
      int t = a[i] - k[i % n];
      if (t < 0)
        t += 52;
      cout << data[t];
    }
    cout << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
int main() {
  char data[53];
  for (int i = 0; i < 26; i++) {
    data[i] = 'A' + i;
    data[i + 26] = 'a' + i;
  }
  int n, k;
  string s;
  while (cin >> n, n) {
    int k[n];
    for (int i = 0; i < n; i++)
      cin >> k[i];
    cin >> s;
    int a[n];
    for (int i = 0; i < s.size(); i++) {
      if (s[i] >= 'a')
        a[i] = 26 + (s[i] - 'a');
      else
        a[i] = s[i] - 'A';
      int t = a[i] - k[i % n];
      if (t < 0)
        t += 52;
      cout << data[t];
    }
    cout << endl;
  }
}
Problem p01620 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<char> cmap;
char getrev(char c, int kagi) {
  int rst;
  if (c >= 'a')
    rst = c - 'a';
  else
    rst = c - 'A' + ('Z' - 'A' + 1);
  if (rst - kagi < 0)
    return cmap[rst - kagi + cmap.size()];
  else
    return cmap[rst - kagi];
}
int main() {
  for (int i = 'a'; i < 'z' + 1; i++)
    cmap.pb(i);
  for (int i = 'A'; i < 'Z' + 1; i++)
    cmap.pb(i);

  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      break;
    int klist[100];
    REP(i, n) { cin >> klist[i]; }
    string ango;
    cin >> ango;
    int nowkagi = 0;
    REP(i, ango.size()) {
      cout << getrev(ango[i], klist[nowkagi]);
      if (nowkagi == n - 1)
        nowkagi = 0;
      else
        nowkagi++;
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define All(X) X.begin(), X.end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<char> cmap;
char getrev(char c, int kagi) {
  int rst;
  if (c >= 'a')
    rst = c - 'a';
  else
    rst = c - 'A' + ('Z' - 'A' + 1);
  if (rst - kagi < 0)
    return cmap[rst - kagi + cmap.size()];
  else
    return cmap[rst - kagi];
}
int main() {
  for (int i = 'a'; i < 'z' + 1; i++)
    cmap.pb(i);
  for (int i = 'A'; i < 'Z' + 1; i++)
    cmap.pb(i);

  while (1) {
    int n;
    cin >> n;
    int klist[100];
    REP(i, n) { cin >> klist[i]; }
    string ango;
    cin >> ango;
    int nowkagi = 0;
    REP(i, ango.size()) {
      cout << getrev(ango[i], klist[nowkagi]);
      if (nowkagi == n - 1)
        nowkagi = 0;
      else
        nowkagi++;
    }
    cout << endl;
  }
}
Problem p01620 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  vector<char> sig;

  for (int i = 0; i < 26; i++)
    sig.push_back((char)('a' + i));
  for (int i = 0; i < 26; i++)
    sig.push_back((char)('A' + i));

  while (cin >> N, N) {
    vector<int> list(N);
    string S;

    for (int i = 0; i < N; i++) {
      cin >> list[i];
    }

    cin >> S;

    for (int i = 0; i < S.size(); i++) {
      int t = find(sig.begin(), sig.end(), S[i]) - sig.begin();
      int key = list[i % list.size()];

      cout << sig[(t - key + 52) % 52];
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stack>
#include <string>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  while (true) {
    string S;
    getline(cin, S);
    if (S == ".")
      break;
    stack<char> stk;
    bool ok = true;
    for (int i = 0; i < (int)S.size(); ++i) {
      if (S[i] == '[') {
        stk.push(S[i]);
      }
      if (S[i] == '(') {
        stk.push(S[i]);
      }
      if (S[i] == ']') {
        if (stk.empty() == false && stk.top() == '[') {
          stk.pop();
        } else {
          ok = false;
          break;
        }
      }
      if (S[i] == ')') {
        if (stk.empty() == false && stk.top() == '(') {
          stk.pop();
        } else {
          ok = false;
          break;
        }
      }
    }
    if (stk.empty() == false)
      ok = false;
    cout << (ok ? "yes" : "no") << endl;
  }
}
Problem p01620 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

char decode(int alph, int n) {
  if (n == 0) {
    return alph;
  }
  if (alph == 'a') {
    return decode('Z', n - 1);
  }
  if (alph == 'A') {
    return decode('z', n - 1);
  }
  return decode(alph - 1, n - 1);
}

int main() {
  int n, l;
  int k[108];
  char s[108];

  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> k[i];
    }
    cin >> s;
    l = strlen(s);

    for (int i = 0; i < l; i++) {
      cout << decode(s[i], k[i % n]);
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

int num[108];

void decode(int l, int k[108], char s[108], char alph[56]) {
  for (int i = 0; i < l; i++) {
    if (s[i] >= 'a' && s[i] <= 'z') {
      num[i] = s[i] - 'a';
    } else {
      num[i] = s[i] - 'A' + 26;
    }
    if (num[i] - k[i] < 0) {
      num[i] += 52 - k[i];
    } else {
      num[i] -= k[i];
    }
    cout << alph[num[i]];
  }
  puts("");
}

int main() {
  int n, m, l;
  int k[108];
  char s[108];
  char alph[56];

  for (int i = 0; i < 26; i++) {
    alph[i] = 'a' + i;
  }
  for (int i = 0; i < 26; i++) {
    alph[i + 26] = 'A' + i;
  }

  while (scanf("%d", &n) != EOF) {
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      cin >> k[i];
    }
    cin >> s;

    m = n;
    l = strlen(s);
    while (l > m) {
      for (int i = 1; i <= n; i++) {
        k[m + i - 1] = k[i - 1];
      }
      m += n;
    }
    decode(l, k, s, alph);
  }
  return 0;
}
Problem p01620 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

#define KEY_NUM 100

char process_key(char c, int key) {

  int num = 0;
  // cout << "[" << c << "," << key << "," << num << "]";
  if ('a' <= c && c <= 'z') {
    num = 25 - (int)('z' - c);
  }
  if ('A' <= c && c <= 'Z') {
    num = 51 - (int)('Z' - c);
  }
  num = (num - key + 104) % 52;
  if (0 <= num && num <= 25) {
    c = 'a' + num;
  }
  if (26 <= num && num <= 51) {
    c = 'A' + (num - 26);
  }
  // cout << "[" << c << "," << key << "," << num << "]";
  return c;
}

int main(void) {
  string s;
  int n;
  int keys[KEY_NUM];
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> keys[i];
    }
    cin >> s;
    // cout << n << endl;
    for (int i = 0; i < s.size(); i++) {
      // cout << process_key(s[i], keys[i % n]) << "_";
      cout << process_key(s[i], keys[i % n]);
    }
    // cout << s << endl;
    cout << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

#define KEY_NUM 52

char process_key(char c, int key) {

  int num = 0;
  // cout << "[" << c << "," << key << "," << num << "]";
  if ('a' <= c && c <= 'z') {
    num = 25 - (int)('z' - c);
  }
  if ('A' <= c && c <= 'Z') {
    num = 51 - (int)('Z' - c);
  }
  num = (num - key) % 52;
  if (0 <= num && num <= 25) {
    c = 'a' + num;
  }
  if (26 <= num && num <= 51) {
    c = 'A' + (num - 26);
  }
  // cout << "[" << c << "," << key << "," << num << "]";
  return c;
}

int main(void) {
  string s;
  int n;
  int keys[KEY_NUM];
  while (cin >> n, n) {
    for (int i = 0; i < n; i++) {
      cin >> keys[i];
    }
    cin >> s;
    // cout << n << endl;
    for (int i = 0; i < s.size(); i++) {
      // cout << process_key(s[i], keys[i % n]) << "_";
      cout << process_key(s[i], keys[i % n]);
    }
    // cout << s << endl;
    cout << endl;
  }
}
Problem p01621 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const char *W[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "All"};
const char *D[] = {"Day", "Night", "All"};

int week, daynight; // 突然変異する曜日, 時間帯

bool isOK(int w, int h) {
  return (week == 7 || week == w) &&
         (daynight == 2 || (daynight == 0) == (6 <= h && h < 18));
}

// jikan wo t dake susumeru
void go(int &w, int &h, int &m, int t) {
  w += t / 1440;
  t %= 1440;
  h += t / 60;
  t %= 60;
  m += t;
  if (m >= 60)
    m -= 60, h++;
  if (h >= 24)
    h -= 24, w++;
  w %= 7;
}

int main() {
  int born, n, end, stage;
  double p;
  char str1[8], str2[8];
  while (~scanf("%d%d%d%s%s%lf%d", &born, &n, &end, str1, str2, &p, &stage) &&
         born != 0) {
    rep(i, 8) if (strcmp(str1, W[i]) == 0) {
      week = i;
      break;
    }
    rep(i, 3) if (strcmp(str2, D[i]) == 0) {
      daynight = i;
      break;
    }
    p = 1 - pow(1 - 1 / p, n);

    double ans = 0;
    rep(w0, 7) rep(h0, 24) rep(m0, 60) { // initial condition
      double tmp = 0;
      int w = w0, h = h0, m = m0;

      double q = p; // 今のステージで突然変異する確率
      rep(i, stage) {
        bool ok1 = isOK(w, h);
        go(w, h, m, born);
        bool ok2 = isOK(w, h);
        go(w, h, m, end - born);
        if (ok1 && ok2)
          tmp += q, q *= 1 - p;
      }
      ans = max(ans, tmp);
    }

    printf("%.9f\\n", ans);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const char *W[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "All"};
const char *D[] = {"Day", "Night", "All"};

int week, daynight; // 突然変異する曜日, 時間帯

inline bool isOK(int w, int h) {
  return (week == 7 || week == w) &&
         (daynight == 2 || (daynight == 0) == (6 <= h && h < 18));
}

int main() {
  int born, n, end, stage;
  double p;
  char str1[8], str2[8];
  while (~scanf("%d%d%d%s%s%lf%d", &born, &n, &end, str1, str2, &p, &stage) &&
         born != 0) {
    rep(i, 8) if (strcmp(str1, W[i]) == 0) {
      week = i;
      break;
    }
    rep(i, 3) if (strcmp(str2, D[i]) == 0) {
      daynight = i;
      break;
    }
    p = 1 - pow(1 - 1 / p, n);

    double ans = 0;
    rep(w0, 7) rep(h0, 24) rep(m0, 60) { // シミュレーションの初期条件
      double tmp = 0;
      int w = w0, h = h0, m = m0;

      double q = p; // 今のステージで突然変異する確率
      rep(i, stage) {
        bool ok = true;
        rep(t, end) {
          if (t <= born && ok && !isOK(w, h))
            ok = false;

          // time++
          if (m < 59)
            m++;
          else if (h < 23)
            m = 0, h++;
          else
            m = 0, h = 0, w = (w + 1) % 7;
        }

        if (ok) {
          tmp += q;
          q *= 1 - p;
        }
      }
      ans = max(ans, tmp);
    }

    printf("%.9f\\n", ans);
  }

  return 0;
}
Problem p01622 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    vector<int> r, w;
    r = w = vector<int>(n);
    int sumR = 0, sumW = 0;
    rep(i, n) {
      cin >> r[i] >> w[i];
      sumR += r[i];
      sumW += w[i];
    }
    vector<int> copyR = r;
    sort(r.begin(), r.end());
    if (sumR >= 2 * r.back()) {
      cout << sumR + sumW << endl;
      continue;
    }
    int gap = 2 * r.back() - sumR;
    vector<int> dp(gap + 1, 0);
    dp[0] = true;
    range(i, 1, n + 1) {
      if (r.back() == copyR[i - 1]) {
        continue;
      }
      for (int j = gap; j >= 0; j--) {
        if (j - w[i - 1] < 0)
          continue;
        dp[j] |= dp[j - w[i - 1]];
      }
    }
    int maxJ = 0;
    rep(j, gap + 1) if (dp[j]) maxJ = max(maxJ, j);
    cout << sumR + sumW + (gap - maxJ) << endl;
  }
  return 0;
}


Error: -6
double free or corruption (out)


Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> r, w;
    r = w = vector<int>(n);
    int sumR = 0, sumW = 0;
    rep(i, n) {
      cin >> r[i] >> w[i];
      sumR += r[i];
      sumW += w[i];
    }

    vector<int> copyR = r;
    sort(r.begin(), r.end());

    if (sumR >= 2 * r.back()) {
      cout << sumR + sumW << endl;
    } else {
      int gap = r.back() - (sumR - r.back());
      vector<vector<int>> dp(n + 1, vector<int>(gap + 1, 0));
      dp[0][0] = true;
      w.erase(w.begin() +
              (copyR.begin() - find(copyR.begin(), copyR.end(), r.back())));
      range(i, 1, n) {
        rep(j, gap + 1) {
          if (j - w[i - 1] < 0)
            continue;
          dp[i][j] |= dp[i - 1][j - w[i - 1]];
        }
      }

      int maxJ = 0;
      rep(i, n + 1) rep(j, gap + 1) if (dp[i][j]) maxJ = max(maxJ, j);
      cout << 2 * r.back() + sumW - maxJ << endl;
    }
  }
  return 0;
}