alexjercan/bugnet huggingface dataset:
Problem p00318 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

bool check(vector<pair<ld, ld>> &ps, ld dis) {
  map<ld, int> mp;
  for (int i = 0; i < ps.size(); ++i) {
    auto p(ps[i]);
    ld d = sqrt(p.second * p.second - dis * dis);
    ld l(p.first - d);
    ld r(p.first + d);
    mp[l]++;
    mp[r]--;
  }
  int num = 0;
  bool flag = false;
  for (auto it = mp.begin(); it != mp.end(); ++it) {
    auto m(*it);
    num += m.second;
    if (num == ps.size())
      flag = true;
  }
  return flag;
}

int main() {
  int N;
  cin >> N;
  vector<pair<ld, ld>> ps;
  ld amin = 0;
  ld amax = 1e18;
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    ps.emplace_back(a, b);
    amax = min(amax, ld(b));
  }

  amax -= 1e-9;
  int kk = 30;
  while (kk--) {
    ld amid((amin + amax) / 2);
    if (check(ps, amid)) {
      amin = amid;
    } else {
      amax = amid;
    }
  }
  cout << setprecision(10) << fixed << amin << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

bool check(vector<pair<ld, ld>> &ps, ld dis) {
  map<ld, int> mp;
  for (int i = 0; i < ps.size(); ++i) {
    auto p(ps[i]);
    ld d = sqrt(p.second * p.second - dis * dis);
    ld l(p.first - d);
    ld r(p.first + d);
    mp[l]++;
    mp[r]--;
  }
  int num = 0;
  bool flag = false;
  for (auto it = mp.begin(); it != mp.end(); ++it) {
    auto m(*it);
    num += m.second;
    if (num == ps.size())
      flag = true;
  }
  return flag;
}

int main() {
  int N;
  cin >> N;
  vector<pair<ld, ld>> ps;
  ld amin = 0;
  ld amax = 1e18;
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    ps.emplace_back(a, b);
    amax = min(amax, ld(b));
  }

  amax -= 1e-9;
  int kk = 40;
  while (kk--) {
    ld amid((amin + amax) / 2);
    if (check(ps, amid)) {
      amin = amid;
    } else {
      amax = amid;
    }
  }
  cout << setprecision(10) << fixed << amin << endl;

  return 0;
}
Problem p00318 (C++) — buggy submission, verdict: Time Limit Exceeded

// 2分探索, 座標圧縮的な何か, imos法
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;

int n;
double x[100000], r[100000];

bool check(double y) {
  int i;
  vector<double> vec;
  static int imos[200001];

  rep(i, n) {
    if (y >= r[i])
      return false;
    double width = sqrt(r[i] * r[i] - y * y);
    vec.push_back(x[i] - width);
    vec.push_back(x[i] + width);
  }
  sort(vec.begin(), vec.end());

  rep(i, 2 * n) imos[i] = 0;

  rep(i, n) {
    double width = sqrt(r[i] * r[i] - y * y);
    int l = lower_bound(vec.begin(), vec.end(), x[i] - width) - vec.begin();
    int r = lower_bound(vec.begin(), vec.end(), x[i] + width) - vec.begin();
    // 区間l,l+1,…,r-1に1を足す
    imos[l]++;
    imos[r]--;
  }

  rep(i, 2 * n) if (i > 0) imos[i] += imos[i - 1];
  rep(i, 2 * n) if (imos[i] == n) return true;
  return false;
}

int main() {
  int i;

  cin >> n;
  rep(i, n) cin >> x[i] >> r[i];

  double st = 0, ed = 1000000, mid; // ooooxxx, [st, ed)
  for (i = 0; i < 50; i++) {
    mid = (st + ed) / 2;
    if (check(mid))
      st = mid;
    else
      ed = mid;
  }
  printf("%.14f\\n", st);
  return 0;
}


Error: TLE

Fixed submission:

// 2分探索, 座標圧縮的な何か, imos法
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;

int n;
double x[100000], r[100000];

bool check(double y) {
  int i;
  vector<double> vec;
  static int imos[200001];

  rep(i, n) {
    if (y >= r[i])
      return false;
    double width = sqrt(r[i] * r[i] - y * y);
    vec.push_back(x[i] - width);
    vec.push_back(x[i] + width);
  }
  sort(vec.begin(), vec.end());

  rep(i, 2 * n) imos[i] = 0;

  rep(i, n) {
    double width = sqrt(r[i] * r[i] - y * y);
    int l = lower_bound(vec.begin(), vec.end(), x[i] - width) - vec.begin();
    int r = lower_bound(vec.begin(), vec.end(), x[i] + width) - vec.begin();
    // 区間l,l+1,…,r-1に1を足す
    imos[l]++;
    imos[r]--;
  }

  rep(i, 2 * n) if (i > 0) imos[i] += imos[i - 1];
  rep(i, 2 * n) if (imos[i] == n) return true;
  return false;
}

int main() {
  int i;

  cin >> n;
  rep(i, n) cin >> x[i] >> r[i];

  double st = 0, ed = 1000000, mid; // ooooxxx, [st, ed)
  for (i = 0; i < 120; i++) {
    mid = (st + ed) / 2;
    if (check(mid))
      st = mid;
    else
      ed = mid;
  }
  printf("%.14f\\n", st);
  return 0;
}
Problem p00320 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int c, q, i, j, z = 0, k = 1, m[1001][1001] = {0}, e[6][2] = {0};
  for (i = 0; i < 6; i++) {
    cin >> q >> c;
    if (q > c)
      m[q][c]++;
    else
      m[c][q]++;
  }
  for (i = 0; i < 1001; i++)
    for (j = 0; j < 1001; j++) {
      if (m[i][j]) {
        if (m[i][j] == 4) {
          e[z][0] = i;
          e[z++][1] = j;
          e[z][0] = i;
          e[z++][1] = j;
        } else if (m[i][j] == 6) {
          e[z][0] = i;
          e[z++][1] = j;
          e[z][0] = i;
          e[z++][1] = j;
          e[z][0] = i;
          e[z++][1] = j;
        } else {
          e[z][0] = i;
          e[z++][1] = j;
        }
      }
    }
  if (e[0][0] != e[2][1] || e[1][0] != e[2][0] || e[0][1] != e[1][1])
    k = 0;
  if (k)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int c, q, i, j, z = 0, k = 1, m[1001][1001] = {0}, e[6][2] = {0};
  for (i = 0; i < 6; i++) {
    cin >> q >> c;
    if (q > c)
      m[q][c]++;
    else
      m[c][q]++;
  }
  for (i = 0; i < 1001; i++)
    for (j = 0; j < 1001; j++) {
      // if(m[i][j]){
      if (m[i][j] == 4) {
        e[z][0] = i;
        e[z++][1] = j;
        e[z][0] = i;
        e[z++][1] = j;
      } else if (m[i][j] == 6) {
        e[z][0] = i;
        e[z++][1] = j;
        e[z][0] = i;
        e[z++][1] = j;
        e[z][0] = i;
        e[z++][1] = j;
      } else {
        e[z][0] = i;
        e[z++][1] = j;
      }
      //}
    }
  if (e[0][0] != e[2][1] || e[1][0] != e[2][0] || e[0][1] != e[1][1])
    k = 0;
  if (k)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}
Problem p00320 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int c, q, i, j, z = 0, k = 1, o = 0, m[1001][1001] = {0}, e[6][2] = {0};
  for (i = 0; i < 6; i++) {
    cin >> q >> c;
    if (q > c)
      m[q][c]++;
    else
      m[c][q]++;
  }
  for (i = 0; i < 1001; i++)
    for (j = 0; j < 1001; j++) {
      if (m[i][j]) {
        if (m[i][j] == 4) {
          e[z][0] = i;
          e[z++][1] = j;
          e[z][0] = i;
          e[z++][1] = j;
        } else if (m[i][j] == 6) {
          e[z][0] = i;
          e[z++][1] = j;
          e[z][0] = i;
          e[z++][1] = j;
          e[z][0] = i;
          e[z++][1] = j;
        } else {
          e[z][0] = i;
          e[z++][1] = j;
        }
      }
    }
  if (e[0][0] != e[2][1] || e[1][0] != e[2][0] || e[0][1] != e[1][1])
    k = 0;
  if (k)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int c, q, i, j, z = 0, k = 1, o = 0, m[1001][1001] = {0}, e[6][2] = {0};
  for (i = 0; i < 6; i++) {
    cin >> q >> c;
    if (q > c)
      m[q][c]++;
    else
      m[c][q]++;
  }
  for (i = 0; i < 1001; i++) {
    for (j = 0; j < 1001; j++) {
      if (m[i][j] == 4) {
        e[z][0] = i;
        e[z++][1] = j;
        e[z][0] = i;
        e[z++][1] = j;
      } else if (m[i][j] == 6) {
        e[z][0] = i;
        e[z++][1] = j;
        e[z][0] = i;
        e[z++][1] = j;
        e[z][0] = i;
        e[z++][1] = j;
      } else {
        e[z][0] = i;
        e[z++][1] = j;
      }
    }
  }
  if (e[0][0] != e[2][1] || e[1][0] != e[2][0] || e[0][1] != e[1][1])
    k = 0;
  if (k)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}
Problem p00320 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int c, q, i, j, z = 0, k = 1, o = 0, m[1001][1001] = {0};
  int a[1001] = {0}, b[1001] = {0}, w[1001] = {0}, e[6][2] = {0};
  for (i = 0; i < 6; i++) {
    cin >> q >> c;
    w[q]++;
    w[c]++;
    if (q > c)
      m[q][c]++;
    else
      m[c][q]++;
  }
  for (i = 0; i < 1001; i++) {
    if (w[i])
      o++;
    for (j = 0; j < 1001; j++) {
      if (m[i][j]) {
        a[j] += m[i][j];
        b[i] += m[i][j];
        if (m[i][j] == 4) {
          e[z][0] = i;
          e[z++][1] = j;
          e[z][0] = i;
          e[z++][1] = j;
        } else if (m[i][j] == 6) {
          e[z][0] = i;
          e[z++][1] = j;
          e[z][0] = i;
          e[z++][1] = j;
          e[z][0] = i;
          e[z++][1] = j;
        } else {
          e[z][0] = i;
          e[z++][1] = j;
        }
      }
    }
  }
  if (e[0][0] != e[2][1] || e[1][0] != e[2][0] || e[0][1] != e[1][1])
    k = 0;
  if (k)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int c, b, i, j, z = 0, k = 1, m[1001][1001] = {0}, e[13][2] = {0};
  for (i = 0; i < 6; i++) {
    cin >> b >> c;
    if (b > c)
      m[b][c]++;
    else
      m[c][b]++;
  }
  for (i = 0; i < 1001; i++)
    for (j = 0; j < 1001; j++) {
      if (m[i][j] == 6) {
        e[z][0] = i;
        e[z++][1] = j;
        e[z][0] = i;
        e[z++][1] = j;
        e[z][0] = i;
        e[z++][1] = j;
      } else if (m[i][j] == 4) {
        e[z][0] = i;
        e[z++][1] = j;
        e[z][0] = i;
        e[z++][1] = j;
      } else {
        e[z][0] = i;
        e[z++][1] = j;
      }
    }
  if (e[0][0] != e[2][1] || e[1][0] != e[2][0] || e[0][1] != e[1][1] > 3)
    k = 0;
  if (k)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
  return 0;
}
Problem p00321 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, f;
  int num = 0;
  map<string, int> mp;
  int con[1001][1001] = {};
  cin >> n >> f;
  string str[1001];
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    vector<string> it(m);

    for (int j = 0; j < m; j++) {
      cin >> it[j];
      if (!mp[it[j]]) {
        num++;
        mp[it[j]] = num;
        str[num] = it[j];
      }
    }
    for (int j = 0; j < m; j++) {
      for (int k = m - 1; k >= 0; k--) {
        if (j == k)
          continue;
        if (it[j] > it[k])
          continue;
        con[mp[it[j]]][mp[it[k]]]++;
      }
    }
  }
  vector<pair<string, string>> ans;
  pair<string, string> abuf;
  int anum = 0;
  for (int i = 1; i <= num; i++) {
    for (int j = 0; j <= num; j++) {
      if (con[i][j] >= f) {
        abuf.first = str[i];
        abuf.second = str[j];
        ans.push_back(abuf);
        anum++;
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << anum << endl;
  for (int i = 0; i < anum; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, f;
  int num = 0;
  map<string, int> mp;
  int con[1001][1001] = {};
  cin >> n >> f;
  string str[1001];
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    vector<string> it(m);

    for (int j = 0; j < m; j++) {
      cin >> it[j];
      if (!mp[it[j]]) {
        num++;
        mp[it[j]] = num;
        str[num] = it[j];
      }
    }
    for (int j = 0; j < m; j++) {
      for (int k = m - 1; k >= 0; k--) {
        if (j == k)
          continue;
        if (it[j] > it[k])
          continue;
        con[mp[it[j]]][mp[it[k]]]++;
      }
    }
  }
  vector<pair<string, string>> ans;
  pair<string, string> abuf;
  int anum = 0;
  for (int i = 1; i <= num; i++) {
    for (int j = 0; j <= 1001; j++) {
      if (con[i][j] >= f) {
        abuf.first = str[i];
        abuf.second = str[j];
        ans.push_back(abuf);
        anum++;
      }
    }
  }
  sort(ans.begin(), ans.end());
  cout << anum << endl;
  for (int i = 0; i < anum; i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
Problem p00321 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  vector<string> Name;
  map<string, int> Relation;
  int k, i, j, n, N, border;
  cin >> N >> border;
  for (k = 0; k < N; k++) {
    cin >> n;
    Name.clear();
    string name;
    for (i = 0; i < n; i++) {
      cin >> name;
      Name.push_back(name);
    }
    for (i = 0; i < n - 1; i++) {
      for (j = i + 1; j < n; j++) {
        if (Name[i] > Name[j])
          Relation[Name[j] + " " + Name[i]]++;
        else
          Relation[Name[i] + " " + Name[j]]++;
      }
    }
  }
  {
    int count = 0;
    for (auto r : Relation) {
      if (r.second >= border)
        count++;
    }
    cout << count << endl;
    for (auto r : Relation) {
      if (r.second >= border)
        cout << r.first << endl;
    }
  }
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  vector<int *> p;
  vector<int> c;
  int k, i, n[9], count = 0;
  {
    int Flags = 0, digit;
    for (k = 0; k < 9; k++) {
      digit = 1;
      cin >> n[k];
      if (n[k] != -1) {
        for (i = 0; i < n[k] - 1; i++)
          digit *= 2;
        Flags += digit;
      } else {
        p.push_back(&n[k]);
      }
    }
    digit = 1;
    for (k = 0; k < 9; k++) {
      if ((Flags & digit) == 0)
        c.push_back(k + 1);
      digit *= 2;
    }
  }
  do {
    for (k = 0; k < c.size(); k++)
      *p[k] = c[k];
    if ((n[0] + n[2] + n[5]) % 10 == n[8]) {
      if ((((n[0] + n[2] + n[5]) / 10) + n[1] + n[4]) % 10 == n[7]) {
        if (((((n[0] + n[2] + n[5]) / 10) + n[1] + n[4]) / 10) + n[3] == n[6]) {
          count++;
        }
      }
    }
  } while (next_permutation(c.begin(), c.end()));
  if (c.size() == 0)
    cout << 1 << endl;
  else
    cout << count << endl;
  return 0;
}
Problem p00323 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int N, S[1000001];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int X, Y;
    cin >> X >> Y;
    S[X + Y]++;
  }
  for (int i = 0; i < 1000000; i++) {
    S[i + 1] += S[i] >> 1;
    if (S[i] & 1)
      cout << i << " " << 0 << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int N, S[200001];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int X, Y;
    cin >> X >> Y;
    S[X + Y]++;
  }
  for (int i = 0; i < 200001; i++) {
    S[i + 1] += S[i] >> 1;
    if (S[i] & 1)
      cout << i << " " << 0 << endl;
  }
}
Problem p00323 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  priority_queue<int, vector<int>, greater<int>> pq;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    pq.push(a + b);
  }
  while (pq.size() > 0) {
    int p = pq.top();
    pq.pop();
    if (pq.size() == 0)
      cout << p << " 0\\n";
    else if (p == pq.top()) {
      pq.pop();
      pq.push(++p);
    } else
      cout << p << " 0\\n";
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int find(vector<int> v, int k) {
  if (v.size() == 0)
    return -1;
  int l = 0, r = v.size() - 1;
  while (l < r - 1) {
    int mid = (l + r) / 2;
    if (v[mid] == k)
      return mid;
    else if (v[mid] < k)
      l = mid;
    else
      r = mid;
  }
  if (v[l] == k)
    return l;
  if (v[r] == k)
    return r;
  return -1;
}
int main() {
  int k;
  cin >> k;
  vector<int> v;
  for (int i = 0; i < k; i++) {
    int p, q;
    cin >> p >> q;
    p += q;
    while (true) {
      int t = find(v, p);
      if (t == -1) {
        v.push_back(p);
        goto heaven;
      } else {
        v.erase(v.begin() + t);
        p++;
      }
    }
  heaven:
    sort(v.begin(), v.end());
  }
  for (int i = 0; i < v.size(); i++)
    cout << v[i] << " 0\\n";
  return 0;
}
Problem p00323 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int N;
  cin >> N;

  const int M = 300000;

  int dp[M] = {};

  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    ++dp[a + b];
  }

  for (int i = 0; i < M - 1; ++i) {
    if (dp[i] & 1)
      cout << i << " " << 0 << endl;
    dp[i + 1] += dp[i] / 2;
  }
}

Error: TLE

Fixed submission:

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

using LL = long long;

int main() {
  int N;
  cin >> N;

  map<int, int> digit;
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    ++digit[a + b];
  }

  auto i = begin(digit);
  while (i != end(digit)) {
    if (i->second & 1)
      cout << i->first << " " << 0 << endl;
    if (i->second < 2)
      ++i;
    else {
      auto nex = i->first + 1;
      if (digit.count(nex))
        digit[nex] += i->second / 2;
      else
        i = digit.insert(pair<int, int>(nex, i->second / 2)).first;
    }
  }
}
Problem p00323 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> line(200020, 0);
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    ++line[a + b];
  }
  for (int i = 0; i < line.size() - 1; ++i) {
    line[i + 1] += line[i] / 2;
    line[i] %= 2;
    if (line[i]) {
      cout << i << " " << 0 << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
#include <vector>
using namespace std;
#define SIZE 200002
vector<set<int>> line(SIZE);
void addnum(int heavy, int num) {
  set<int>::iterator itr = line[heavy].find(num);
  if (itr == line[heavy].end()) {
    line[heavy].insert(num);
  } else {
    line[heavy].erase(num);
    addnum(heavy, num + 1);
  }
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int a, b;
    cin >> a >> b;
    addnum(a, b);
  }
  for (int i = 0; i < line.size(); ++i) {
    for (set<int>::iterator itr = line[i].begin(); itr != line[i].end();
         ++itr) {
      if (*itr == 0) {
        cout << i << " " << 0 << endl;
      } else {
        addnum(i + 1, *itr - 1);
      }
    }
    line[i].clear();
  }
  return 0;
}
Problem p00323 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#define INF 210000
using namespace std;
int c[INF];
int main() {
  int n, a, b;
  for (int i = 0; i < INF; i++)
    c[i] = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    c[a + b]++;
  }
  for (int i = 0; i < INF - 1; i++) {
    c[i + 1] += c[i] / 2;
    if (c[i] % 2)
      cout << i << " 0" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#define INF 210000
using namespace std;
int c[INF];
int main() {
  int n, a, b;
  for (int i = 0; i < INF; i++)
    c[i] = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    c[a + b]++;
  }
  for (int i = 0; i < INF; i++) {
    c[i + 1] += c[i] / 2;
    if (c[i] % 2)
      cout << i << " 0" << endl;
  }
  return 0;
}
Problem p00323 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, a, b;
  vector<int> v;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    v.push_back(a + b);
  }

  sort(v.begin(), v.end());
  while (1) {
    int cnt = 1;
    bool check = true;
    vector<int> t;

    for (int i = 0; i < v.size(); ++i) {
      if (i != v.size() - 1 && v[i] == v[i + 1]) {
        cnt++;
      } else {
        if (cnt >= 2)
          check = false;

        if (cnt % 2 == 1)
          t.push_back(v[i]);
        for (int j = 0; j < cnt / 2; ++j) {
          t.push_back(v[i] + 1);
        }

        cnt = 1;
      }
    }

    if (check)
      break;

    v = t;
  }

  for (auto elem : v) {
    cout << elem << " " << 0 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, a, b;
  vector<int> v, t;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    v.push_back(a + b);
  }

  sort(v.begin(), v.end());
  while (1) {
    int cnt = 1;
    bool check = true;
    for (int i = 0; i < v.size(); ++i) {
      if (i != v.size() - 1 && v[i] == v[i + 1]) {
        cnt++;
      } else {
        if (cnt >= 2)
          check = false;

        for (int j = 0; j < cnt / 2; ++j) {
          t.push_back(v[i] + 1);
        }
        if (cnt % 2 == 1)
          t.push_back(v[i]);

        cnt = 1;
      }
    }

    if (check)
      break;

    v = t;
  }

  for (auto elem : v) {
    cout << elem << " " << 0 << endl;
  }

  return 0;
}
Problem p00324 (C++) — buggy submission, verdict: Time Limit Exceeded

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

long long int d[200002];
long long int r[200003];
map<long long int, int> m;

int main() {

  int ans = 0, n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    scanf(" %lld", &d[i]);
  }

  for (int i = 0; i < n; i++) {
    r[i + 1] = d[i] + r[i];
  }

  for (int i = 0; i < n + 1; i++) {
    if (m[r[i]] == 0 && r[i] != 0) {
      m[r[i]] = i;
    } else {
      ans = max(ans, i - m[r[i]]);
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

long long int d[200001];
long long int r[200002];

int main() {

  int ans = 0, n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    scanf(" %lld", &d[i]);
  }

  for (int i = 0; i < n; i++) {
    r[i + 1] = d[i] + r[i];
  }

  for (int i = 0; i < n + 1; i++) {
    for (int j = i; j < n + 1; j++) {
      if (r[j] - r[i] == 0) {
        ans = max(ans, j - i);
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p00324 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  map<long long, int> m;
  long long n, ans = 0, a[200000], x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    a[i] = i ? a[i - 1] + x : x;
    if (!m[a[i]])
      m[a[i]] = i + 1;
  }
  for (int i = 0; i < n; i++) {
    if (m[a[i]])
      if (i - m[a[i]] + 1 > ans)
        ans = i - m[a[i]] + 1;
    if (!a[i])
      ans = i + 1;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j, c, k, m, l;
  cin >> n;
  long long a[n];
  for (i = l = 0; i < n; i++)
    cin >> a[i];
  for (i = 0; i < n; i++) {
    for (j = i, c = m = k = 0; j < n; j++) {
      c += a[j];
      if (c == 0)
        k = 1 + j - i;
      m = max(k, m);
    }
    l = max(m, l);
  }
  for (i = n - 1; i >= 0; i--) {
    for (j = i, c = m = k = 0; j >= 0; j--) {
      c += a[j];
      if (c == 0)
        k = i - j;
      m = max(k, m);
    }
    l = max(m, l);
  }
  cout << l << endl;
}