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

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
map<int, int> M;
int x, n, T = 0;
int main() {
  int bj = 0, maxn = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (bj) {
      puts("No");
      continue;
    }
    if (x <= T) {
      //			cout<<maxn<<endl;
      if (maxn > x)
        puts("No");
      else
        puts("Yes"), bj = 1;
      continue;
    }
    maxn = max(maxn, x);
    M[x]++;
    puts("Yes");
    while (M[x] == 2) {
      maxn = maxn == x ? maxn - 1 : maxn;
      M[x] = 0;
      M[--x]++;
    }
    while (M[T + 1])
      T++;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lowbit(x) (x & (-x))
typedef long long ll;
int a[500010] = {0};
int main() {
  int n, mm = 0;
  ;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    if (x >= 500002) {
      mm++;
      puts("Yes");
      continue;
    }
    int c = x;
    if (a[0]) {
      puts("No");
      continue;
    }
    if (a[x] == 0) {
      a[x] = 1;
      mm++;
      puts("Yes");
    } else {
      int nm = 0;
      while (c >= 1 && a[c] == 1) {
        c--;
        nm++;
      }
      if (c == 0) {
        if (nm == mm) {
          mm++;
          a[c] = 1;
          puts("Yes");
          continue;
        } else {
          puts("No");
          continue;
        }
      }
      if (a[c] == 0) {
        for (int j = c + 1; j <= x; j++) {
          a[j] = 0;
          mm--;
        }
        mm++;
        a[c] = 1;
        puts("Yes");
      }
    }
  }
}
Problem p00952 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define inf 1000050
using namespace std;
int top, ntop, a[inf + 10], n, ll;
int add(int ll) {
  if (a[0] == 1)
    return 0;
  if (ll < top)
    return 0;
  if (a[ll] == 0) {
    a[ll] = 1;
    if (ntop < ll)
      ntop = ll;
    return 1;
  }
  int xx = ll;
  while ((a[ll] == 1) && (ll >= 1)) {
    a[ll] = 0;
    ll--;
  }
  a[ll] = 1;
  if (a[0] == 1) {
    if (xx < ntop) {
      a[0] = 0;
      for (int i = 1; i <= xx; i++)
        a[i] = 1;
      return 0;
    }
  }
  return 1;
}
int check() {
  while (a[top + 1])
    top++;
  while (a[ntop] == 0)
    ntop--;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &ll);
    if (ll > inf) {
      printf("Yes\\n");
      continue;
    }
    if (add(ll))
      printf("Yes\\n");
    else
      printf("No\\n");
    check();
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define LL long long
#define INF (2147483647)
#define sqr(x) ((x) * (x))
#define mod (1000000007)
using namespace std;
inline void read(int &data) {
  data = 0;
  int w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = data * 10 + ch - '0', ch = getchar();
  data = data * w;
}
inline void read(LL &data) {
  data = 0;
  int w = 1;
  char ch = 0;
  while (ch != '-' && (ch < '0' || ch > '9'))
    ch = getchar();
  if (ch == '-')
    w = -1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    data = data * 10 + ch - '0', ch = getchar();
  data = data * w;
}
inline void write(int x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
inline void write(LL x) {
  if (x < 0)
    putchar('-'), x = -x;
  if (x > 9)
    write(x / 10);
  putchar(x % 10 + '0');
}
int a[1000005], n, k, ans = 0;
int main() {
  read(n);
  rep(i, 1, n) {
    read(k);
    if (k > 2 * n) {
      puts("Yes");
      continue;
    }
    ans++;
    int j = k;
    while (a[j] == 1)
      j--;
    if (j == 0 && ans - (k - j) > 1 || a[0] == 1)
      puts("No");
    else {
      rep(kk, j + 1, k) a[kk] = 0;
      a[j] = 1;
      puts("Yes");
      ans -= (k - j);
    }
  }
}
Problem p00952 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n;
  cin >> n;
  int x[n];
  for (int i = 0; i < n; i++)
    scanf("%lld", x + i);
  set<int> s;
  int u = 1;
  for (int i = 0; i < n; i++) {
    if (s.count(0)) {
      cout << "No" << endl;
      continue;
    }
    int k = x[i];
    while (s.count(u))
      u++;
    if (k < u - 1 || (k == u - 1 && (int)s.size() != u - 1)) {
      puts("No");
      continue;
    }
    puts("Yes");
    while (s.count(k))
      s.erase(k--);
    s.insert(k);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n;
  cin >> n;
  int x[n];
  for (int i = 0; i < n; i++)
    cin >> x[i];
  set<int> s, u;
  for (int i = 0; i < n; i++) {
    // cout<<i<<":"<<x[i]<<endl;
    if (s.count(0)) {
      cout << "No" << endl;
      continue;
    }
    if (!s.count(x[i])) {
      s.insert(x[i]);
      cout << "Yes" << endl;
    } else {
      int k = x[i], c = 0;
      while (s.count(k) && !u.count(k))
        k--, c++;
      // cout<<x[i]<<":"<<k<<"-"<<c<<"="<<s.size()<<endl;
      // cout<<"u:";for(int j:s) cout<<" "<<j;cout<<endl;
      if (k == 0) {
        if ((int)s.size() == c) {
          cout << "Yes" << endl;
          for (int j = x[i]; j > k; j--)
            s.erase(j);
          s.insert(k);
        } else {
          cout << "No" << endl;
          for (int j = k; j <= x[i]; j++)
            u.insert(j);
        }
        continue;
      }
      if (u.count(k)) {
        cout << "No" << endl;
        // for(int j=k;j<=x[i];j++) u.insert(j);
      } else {
        cout << "Yes" << endl;
        for (int j = x[i]; j > k; j--)
          s.erase(j);
        s.insert(k);
      }
    }
  }
  return 0;
}
Problem p00952 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int n;
const int MAX = 1000006;

class BIT {
  int n, bit[MAX + 2];

public:
  BIT(int n = MAX) : n(n) { fill(bit, bit + MAX + 1, 0); }

  void add(int i, int x) {
    while (i <= n) {
      bit[i] += x;
      i += i & -i;
    }
  }
  int sum(int i) {
    int s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }
};

BIT used;
void view() {
  for (int i = 1; i < 10; i++)
    cout << used.sum(i) - used.sum(i - 1) << " ";
  cout << endl;
}

int main() {
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    x++;
    int t = x;
    if (used.sum(1)) {
      cout << "No" << endl;
    } else if (x > 1000000) {
      cout << "Yes" << endl;
    } else if (used.sum(x) == x - 1 && used.sum(MAX) > x - 1)
      cout << "No" << endl;
    else {
      cout << "Yes" << endl;
      while (used.sum(x) - used.sum(x - 1))
        used.add(x--, -1);
      used.add(x, 1);
    }
    // view();
  }
}

Error: TLE

Fixed submission:

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

int n;
bool used[1000005];
void view() {
  for (int i = 0; i < 10; i++)
    cout << used[i] << " ";
  cout << endl;
}
int main() {
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int t = x;
    if (used[0]) {
      cout << "No" << endl;
      continue;
    }
    if (x > 1000000) {
      cout << "Yes" << endl;
      continue;
    }
    while (used[x]) {
      used[x--] = false;
      cnt--;
    }
    used[x] = true;
    cnt++;
    // cout <<cnt << endl;
    // view();
    if (used[0] && cnt > 1) {
      cout << "No" << endl;
      for (int i = t; i > x; i--) {
        used[i] = true;
        cnt++;
      }
      used[x] = false;
      cnt--;
      // cout <<cnt << endl;
      // view();
    } else
      cout << "Yes" << endl;
  }
}
Problem p00952 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1 << 29)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define uniq(v) v.erase(unique(all(v)), v.end())

#define MAXN 500000

bitset<1000000001> b;
bool full[MAXN + 1 + 1];
int lowest = -1;

bool ok(int depth) {
  if (b[0])
    return false;
  return depth >= MAXN || !full[depth] || depth >= lowest;
}

void add(int depth) {
  lowest = max(lowest, depth);
  while (1) {
    if (b[depth]) {
      b.reset(depth--);
    } else {
      b.set(depth);
      break;
    }
  }
  if (!b[lowest])
    lowest = depth;
  if (depth == 0 || depth >= MAXN)
    return;
  while (full[depth - 1] && !full[depth] && b[depth]) {
    full[depth++] = true;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  full[0] = true;
  int n;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    if (ok(x)) {
      add(x);
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1 << 29)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define uniq(v) v.erase(unique(all(v)), v.end())

#define MAXN 500000

bitset<1000000001> b;
bool full[MAXN + 1 + 1];
int lowest = -1;

bool ok(int depth) {
  if (b[0])
    return false;
  return depth > MAXN || !full[depth] || depth >= lowest;
}

void add(int depth) {
  lowest = max(lowest, depth);
  while (1) {
    if (b[depth]) {
      if (lowest == depth)
        lowest--;
      b.reset(depth--);
    } else {
      b.set(depth);
      break;
    }
  }
  if (depth == 0)
    return;
  while (full[depth - 1] && !full[depth] && b[depth]) {
    full[depth++] = true;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  full[0] = true;
  int n;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    if (ok(x)) {
      add(x);
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

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

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1 << 29)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define uniq(v) v.erase(unique(all(v)), v.end())

#define MAXN 500000

bitset<MAXN + 1 + 1> b;
bool full[MAXN + 1 + 1];
int lowest = -1;

bool ok(int depth) {
  if (b[0])
    return false;
  return depth > MAXN || !full[depth] || depth >= lowest;
}

void add(int depth) {
  lowest = max(lowest, depth);
  if (depth >= MAXN)
    return;
  while (1) {
    if (b[depth]) {
      b.reset(depth--);
    } else {
      b.set(depth);
      break;
    }
  }
  if (lowest <= MAXN && !b[lowest])
    lowest = depth;
  if (depth == 0)
    return;
  while (full[depth - 1] && !full[depth] && b[depth]) {
    full[depth++] = true;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  full[0] = true;
  int n;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    if (ok(x)) {
      add(x);
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1 << 29)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define uniq(v) v.erase(unique(all(v)), v.end())

#define MAXN 500000

bitset<MAXN + 1 + 1> b;
bool full[MAXN + 1 + 1];
int lowest = -1;

bool ok(int depth) {
  if (b[0])
    return false;
  return depth > MAXN || !full[depth] || depth >= lowest;
}

void add(int depth) {
  lowest = max(lowest, depth);
  if (depth >= MAXN)
    return;
  while (1) {
    if (b[depth]) {
      b.reset(depth--);
    } else {
      b.set(depth);
      break;
    }
  }
  if (!b[lowest])
    lowest = depth;
  if (depth == 0)
    return;
  while (full[depth - 1] && !full[depth] && b[depth]) {
    full[depth++] = true;
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);

  full[0] = true;
  int n;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    if (ok(x)) {
      add(x);
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

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

#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int n, x, b[500029], r = 1, sum;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    if (b[0])
      puts("No");
    else if (x >= 500020)
      puts("Yes");
    else {
      while (b[r])
        r++;
      if (r <= x) {
        puts("Yes");
        int z = x;
        b[z]++, sum++;
        while (b[z] == 2)
          b[z] = 0, b[--z]++, sum--;
        r = min(r, z + 1);
      } else {
        if (sum == x)
          puts("Yes"), b[0] = 1;
        else
          puts("No");
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int n, x, b[500029], sum;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    if (b[0])
      puts("No");
    else if (x >= 500020)
      puts("Yes");
    else {
      int r = 1;
      while (b[r])
        r++;
      if (r <= x) {
        puts("Yes");
        int z = x;
        b[z]++, sum++;
        while (b[z] == 2)
          b[z] = 0, b[--z]++, sum--;
      } else {
        if (sum == x)
          puts("Yes"), b[0] = 1;
        else
          puts("No");
      }
    }
  }
  return 0;
}
Problem p00952 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define N 10000001
using namespace std;
bool num[N];
int top;

bool compare(int x) { return top >= 0 && top >= max(0, N - x - 1); }

void Minus(int x) {
  while (1) {
    num[x] = !num[x];
    if (num[x] == 0)
      break;
    x++;
  }
  while (top >= 0 && num[top] == 0)
    top--;
}

int main() {
  int n;
  cin >> n;
  num[N - 1] = 1;
  top = N - 1;
  while (n--) {
    int x;
    scanf("%d", &x);
    if (top >= 0 && compare(x))
      printf("Yes\\n"), Minus(max(0, N - x - 1));
    else
      printf("No\\n");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define N 1000000
using namespace std;
bool num[N];
int top;

bool compare(int x) { return top >= N - x - 1; }

void Minus(int x) {
  if (x >= N)
    return;
  while (1) {
    num[x] = !num[x];
    if (num[x] == 0)
      break;
    x++;
  }
  while (top >= 0 && num[top] == 0)
    top--;
}

int main() {
  int n;
  cin >> n;
  num[N - 1] = 1;
  top = N - 1;

  while (n--) {
    int x;
    scanf("%d", &x);
    if (compare(x))
      printf("Yes\\n"), Minus(N - x - 1);
    else
      printf("No\\n");
  }
  return 0;
}
Problem p00952 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int A[N];

int main() {

  int n, x;
  cin >> n;

  int max1 = 0, min0 = 0;

  for (int i = 0; i < n; i++) {

    scanf("%d", &x);

    if (A[0] == 1)
      printf("No\\n");
    else if (x >= n + 3)
      printf("Yes\\n");
    else {

      if (min0 >= x && x < max1) {
        printf("No\\n");
        continue;
      }

      printf("Yes\\n");

      int f = 0;
      if (max1 == x)
        f = 1;

      A[x]++;

      while (A[x] == 2) {
        A[x] = 0;
        A[--x]++;
      }

      if (f || max1 < x)
        max1 = x;

      x = max(1, min0);

      while (A[x] == 1) {
        min0 = x;
        x++;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

int A[N];

int main() {

  int n, x;
  cin >> n;

  int max1 = 0, min0 = 0;

  for (int i = 0; i < n; i++) {

    scanf("%d", &x);

    if (A[0] == 1)
      printf("No\\n");
    else if (x >= n + 3)
      printf("Yes\\n");
    else {

      if (min0 > x || (min0 == x && x < max1)) { // min0 >= x && x < max1
        printf("No\\n");
        continue;
      }

      printf("Yes\\n");

      int f = 0;
      if (max1 == x)
        f = 1;

      A[x]++;

      while (A[x] == 2) {
        A[x] = 0;
        A[--x]++;
      }

      if (f || max1 < x)
        max1 = x;

      if (A[1] == 1) {

        min0 = 0;
        x = 1;
        while (A[x] == 1) {
          min0 = x;
          x++;
        }
      }
    }
  }

  return 0;
}
/*
0 1 1 1 1 0 0 1 0 1 1 0 1 0
        v               v
        min0            max1
*/
Problem p00954 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
void gce(int a, int b, int &x, int &y) {
  if (!b) {
    x = 1;
    y = 0;
    return;
  }
  gce(b, a % b, x, y);
  int t = x;
  x = y;
  y = t - a / b * x;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, m;
    scanf("%d%d", &n, &m);
    int g = __gcd(n, m);
    if (g <= 50000) {
      int a, b;
      gce(n, m, a, b);
      if (a <= 0)
        printf("3\\n0 0\\n%d% d\\n%d %d\\n", n, m, b, -a);
      else
        printf("3\\n0 0\\n%d% d\\n%d %d\\n", n, m, -b, a);
    } else {
      printf("4\\n0 0\\n%d %d\\n%d %d\\n%d %d\\n", n, m - 1, n / g, m / g, n - 1, m);
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn_x = 5010;
const int maxn_y = 5010;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
double dis(int x1, int y1, int x2, int y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double cal_tri(int x1, int y1, int x2, int y2, int x3, int y3) {
  double len_1 = dis(x1, y1, x2, y2);
  double len_2 = dis(x1, y1, x3, y3);
  double len_3 = dis(x2, y2, x3, y3);
  double p = (len_1 + len_2 + len_3) / 2;
  return sqrt(p * (p - len_1) * (p - len_2) * (p - len_3));
}
double cal(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
  return cal_tri(x1, y1, x2, y2, x3, y3) + cal_tri(x1, y1, x4, y4, x3, y3);
}
queue<pair<int, int>> q;
int check(int tx, int ty, int x, int y) {
  if (tx == x - 1 && ty == y)
    return 0;
  if (tx == 0 && ty == 0)
    return 0;
  if (tx == x && ty == y - 1)
    return 0;
  return 1;
}
int vis[maxn_x][maxn_y];
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    int x, y;
    srand(time(0));
    scanf("%d%d", &x, &y);
    if (x == y)
      printf("4\\n%d %d\\n%d %d\\n%d %d\\n%d %d\\n", 0, 0, x - 1, x, 1, 1, x, x - 1);
    else {
      int xx, yy;
      if (cal(0, 0, x - 1, y, 1, 1, x, y - 1) < 25000) {
        printf("4\\n%d %d\\n%d %d\\n%d %d\\n%d %d\\n", 0, 0, x - 1, y, 1, 1, x,
               y - 1);
        continue;
      }
      while (1) {
        int max_x = min(1010, x);
        int max_y = min(1010, y);
        xx = rand() % max_x;
        yy = rand() % max_y;
        if (!check(xx, yy, x, y))
          continue;
        if (cal(0, 0, x - 1, y, xx, yy, x, y - 1) < 25000) {
          printf("4\\n%d %d\\n%d %d\\n%d %d\\n%d %d\\n", 0, 0, x - 1, y, xx, yy, x,
                 y - 1);
          break;
        }
      }
    }
  }
}
Problem p00957 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
using namespace std;
long long f[1000000];
int main() {
  long long l, k;
  for (int i = 1; i <= 1000; i++) {
    f[i] = 0;
  }
  scanf("%lld%lld", &l, &k);
  f[1] = 1;
  f[k] = 1;
  long long ans = 0;
  for (int i = 1; i <= l; i++) {
    f[i + 2] += f[i];
    f[i + k + 1] += f[i];
    ans += f[i];
  }
  printf("%lld\\n", ans);
  return 0;
}


Error: -11

Fixed submission:

#include <cstdio>
using namespace std;
long long f[1000];
int main() {
  long long l, k;
  for (int i = 1; i <= 100; i++) {
    f[i] = 0;
  }
  scanf("%d%d", &l, &k);
  f[1] = 1;
  f[k] = 1;
  long long ans = 0;
  for (int i = 1; i <= l; i++) {
    f[i + 2] += f[i];
    f[i + k + 1] += f[i];
    ans += f[i];
  }
  printf("%lld\\n", ans);
  return 0;
}
Problem p00957 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

class SecretOfChocolatePoles {
public:
  SecretOfChocolatePoles(int l, int k) : l(l), k(k), dp(l + 1){};

  long long Count() {
    dp[1] = 1;
    if (k <= l)
      dp[k] = 1;
    for (int h = 2; h <= l; ++h) {
      if (0 <= h - 2)
        dp[h] += dp[h - 2];
      if (0 <= h - k - 1)
        dp[h] += dp[h - k - 1];
    }

    return accumulate(dp.begin(), dp.end(), 0LL);
  }

private:
  int l, k;
  vector<long long> dp;
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int l, k;
  cin >> l >> k;
  SecretOfChocolatePoles scp(l, k);
  cout << scp.Count() << '\\n';

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

class SecretOfChocolatePoles {
public:
  SecretOfChocolatePoles(int l, int k) : l(l), k(k), dp(l + 1){};
  long long Count() {
    dp[1] = 1;
    dp[k] = 1;
    for (int h = 2; h <= l; ++h) {
      if (0 <= h - 2)
        dp[h] += dp[h - 2];
      if (0 <= h - k - 1)
        dp[h] += dp[h - k - 1];
    }

    return accumulate(dp.begin(), dp.end(), 0LL);
  }

private:
  int l, k;
  vector<long long> dp;
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int l, k;
  cin >> l >> k;
  SecretOfChocolatePoles scp(l, k);
  cout << scp.Count() << '\\n';

  return 0;
}