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

#include <iostream>

using namespace std;

int n;

bool tansaku(int tt[]) {
  int max = 0;
  for (int i = 0; i < n; i++) {
    max = max > i + tt[i] ? max : i + tt[i];
    if (max >= n) {
      return true;
    } else if (i + 1 > max) {
      break;
    }
  }
  return false;
}

int main() {
  int tt1[300000];
  int tt2[300000];
  cin >> n;

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

    tt1[i] = t / 10;
    tt2[n - 1 - i] = t / 10;
  }
  if (tansaku(tt1) && tansaku(tt2)) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <queue>

using namespace std;

int n;

bool tansaku(int jump[]) {
  queue<int> q;

  q.push(0); // スタートを代入

  // キューが空になるまで繰り返す
  while (q.size() > 0) {
    // 現在の位置
    int idx = q.front();
    q.pop();

    // 移動できる位置を追加
    for (int i = 1; i <= (jump[idx] / 10); i++) {
      if (idx + i == n) {
        return true;
      }
      q.push(idx + i);
    }
  }
  return false;
}

bool tansaku2(int jump[]) {
  int a[300000];

  // 初期化
  for (int i = 0; i <= n; i++) {
    a[i] = 0;
  }

  a[0] = 1;
  for (int i = 0; i < n; i++) {
    // 到達可能な場所か？（到達しているか？）
    if (a[i] == 0)
      continue;

    // 移動できる位置を追加
    for (int j = 1; j <= (jump[i] / 10); j++) {
      if (i + j == n) {
        return true;
      }
      a[i + j] = 1;
    }
  }
  return false;
}

int main() {
  cin >> n;

  int jump1[300000];
  int jump2[300000];

  // 入力
  for (int i = 0; i < n; i++) {
    cin >> jump1[i];
    jump2[n - 1 - i] = jump1[i];
  }

  if (tansaku2(jump1) && tansaku2(jump2)) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }

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

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

int main() {
  int n;
  cin >> n;
  int D;

  int d[300000];
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < n - 1; i++) {
    D = max(D, d[i]);

    if (D < 10) {
      cout << "no" << endl;
      return 0;
    }
    D -= 10;
  }
  D = 0;

  for (int i = n - 1; i > 0; i--) {
    D = max(D, d[i]);

    if (D < 10) {
      cout << "no" << endl;
      return 0;
    }
    D -= 10;
  }
  cout << "yes" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int max(int d[], int h, int t) {
  int max = h;
  if (h == t) {
    return max;
  }
  for (int i = h + 1; i < t; i++) {
    if (d[max] < d[i]) {
      max = i;
    }
  }
  return max;
}
bool leftjump(int d[], int n) {
  int i = 1;
  int r = d[0];
  while (i < n) {
    if (r < 10) {
      return false;
    }
    int tmp = i;
    i = max(d, i, i + r / 10);
    r = r - (10 * (i - tmp)) + d[i];
  }
  return true;
}

bool rightjump(int d[], int n) {
  int i = n;
  int r = d[n - 1];
  while (i >= 0) {
    if (r < 10) {
      return false;
    }
    int tmp = i;
    i = max(d, i - r / 10, i);
    r = r - (10 * (tmp - i)) + d[i];
  }
  return true;
}
int main() {
  int N;
  cin >> N;
  int d[N];
  int count = 0;
  for (int i = 0; i < N; i++) {
    cin >> d[i];
    if (d[i] >= 10) {
      count++;
    }
  }

  if (count == N) {
    cout << "yes" << endl;
    return 0;
  }

  if (leftjump(d, N) && rightjump(d, N)) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return 0;
}
Problem p00357 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod (ll)(1e9 + 7)
#define int ll

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n;
int t[300001];

signed main() {
  cin >> n;
  rep(i, 0, n) cin >> t[i];

  int mx = 0;
  rep(i, 0, n) {
    if (i * 10 > mx) {
      cout << "no" << endl;
      return 0;
    }
    mx = max(mx, i * 10 + t[i]);
  }
  mx = 0;
  int cu = 0;
  dep(i, n - 1, 0) {
    if (cu * 10 > mx) {
      cout << "no" << endl;
      return 0;
    }
    mx = max(mx, cu * 10 + t[i]);
    cu++;
  }
  cout << "yes" << endl;
}


Error: 0

Fixed submission:

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod (ll)(1e9 + 7)
#define int ll

__attribute__((constructor)) void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  int t[100001];
  rep(i, 0, n) cin >> t[i];

  int mx = 0;
  rep(i, 0, n) {
    if (i * 10 > mx) {
      cout << "no" << endl;
      return 0;
    }
    mx = max(mx, i * 10 + t[i]);
  }
  mx = 0;
  int cu = 0;
  dep(i, n - 1, 0) {
    if (cu * 10 > mx) {
      cout << "no" << endl;
      return 0;
    }
    mx = max(mx, cu * 10 + t[i]);
    cu++;
  }
  cout << "yes" << endl;
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int d[n];
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  int l = 0;
  bool ok = false;
  for (int i = 0; i < n; i++) {
    if (l < 0)
      break;
    if (i == n - 1)
      ok = true;
    l = max(l, d[i]);
    l -= 10;
  }
  if (!ok) {
    cout << "no" << endl;
    return 0;
  }
  l = 0;
  ok = false;
  for (int i = n - 1; i >= 0; i--) {
    if (l < 0)
      break;
    if (i == 0)
      ok = true;
    l = max(l, d[i]);
    l -= 10;
  }
  if (!ok) {
    cout << "no" << endl;
    return 0;
  }

  cout << "yes" << endl;
}

Error: TLE

Fixed submission:

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

using namespace std;

void dfs(int id, int d[], bool vis[], int n, bool kk) {
  vis[id] = true;
  int tmp = d[id];
  for (int i = 0; i <= tmp; i++) {
    if (kk && i + id < n && !vis[i + id]) {
      dfs(i + id, d, vis, n, true);
    }
    if (!kk && id - i >= 0 && !vis[id - i]) {
      dfs(id - i, d, vis, n, false);
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int d[n];
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  for (int i = 0; i < n; i++) {
    d[i] /= 10;
  }
  bool vis[n];
  for (int i = 0; i < n; i++) {
    vis[i] = false;
  }
  dfs(0, d, vis, n, true);
  if (!vis[n - 1]) {
    cout << "no" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    vis[i] = false;
  }
  dfs(n - 1, d, vis, n, false);
  if (!vis[0]) {
    cout << "no" << endl;
    return 0;
  }
  cout << "yes" << endl;
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
#define put(n) cout << (n) << "\\n"
#define FOR(i, num, N) for (int(i) = (num); (i) < (N); ++(i))
#define RFOR(i, num, N) for (int(i) = (num); (i) > (N); --(i))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

int main() {
  int N, left, right;
  cin >> N;
  vector<int> T(N);
  FOR(i, 0, N) cin >> T[i];

  left = T[0] / 10;
  for (int i = 1; left >= i && i < N; ++i) {
    left = max(left, T[i] / 10 + i);
  }

  reverse(T.begin(), T.end());

  right = T[0] / 10;
  for (int i = 1; right >= i && i < N; ++i) {
    right = max(right, T[i] / 10 + i);
  }

  if (left >= N - 1 && right >= N - 1)
    cout << "yes\\n";
  else
    cout << "no\\n";
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(i, j, n) for (int i = (j); i < (n); i++)
#define rep2(i, j, n) for (int i = (j); i <= (n); i++)
#define all(i) i.begin(), i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

vector<bool> vec;
vector<int> jump;

int N;

void go(int i, int step) {
  for (int j = i + 1; j <= i + step && j < N; j++) {
    if (j)
      vec[j] = true;
  }
}

int main() {
  cin >> N;
  vec.assign(N, false);

  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    jump.push_back(x / 10);
  }

  for (int i = 0; i < N; i++) {
    go(i, jump[i]);
  }

  vec[0] = true;

  for (auto p : vec) {
    if (p == false) {
      cout << "no\\n";
      return 0;
    }
  }

  vec.assign(N, false);

  vec[0] = true;

  reverse(all(jump));

  for (int i = 0; i < N; i++) {
    go(i, jump[i]);
  }

  for (auto p : vec) {
    if (p == false) {
      cout << "no\\n";
      return 0;
    }
  }

  cout << "yes\\n";
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LL long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
//
int N;
VE D;
bool DFS(int now, int nok) {
  if (nok < 10) {
    return false;
  } else if (now == N - 1) {
    return true;
  }
  now++;
  nok -= 10;
  if (DFS(now, max(D[now], nok))) {
    return true;
  }
  return false;
}
int main() {
  cin >> N;
  FOR(i, 0, N) {
    int d;
    cin >> d;
    D.PB(d);
  }
  if (!DFS(0, D[0])) {
    cout << "no" << endl;
    return 0;
  }
  reverse(D.begin(), D.end());
  if (!DFS(0, D[0])) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LL long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
//
int N;
VE D;
bool DFS(int now, int nok) {
  if (nok < 10) {
    return false;
  } else if (now == N - 1) {
    return true;
  }
  now++;
  nok -= 10;
  if (DFS(now, D[now])) {
    return true;
  }
  if (DFS(now, nok)) {
    return true;
  }
  return false;
}
int main() {
  cin >> N;
  FOR(i, 0, N) {
    int d;
    cin >> d;
    D.PB(d);
  }
  if (!DFS(0, D[0])) {
    cout << "no" << endl;
    return 0;
  }
  reverse(D.begin(), D.end());
  if (!DFS(0, D[0])) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }
  return 0;
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int N;
  int MAX = 0;
  int MIN = 0;
  bool task1 = false;
  bool task2 = false;
  static int d[300000];
  static int should[300000];

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  int plan = 0;
  while (1) {
    if (d[plan] + (plan * 10) > MAX) {
      if (d[plan] > 9) {
        MAX = d[plan] + (plan * 10);
        if (MAX >= (N - 1) * 10) {
          task1 = true;
          break;
        }
      }
    }
    if (MAX < (plan + 1) * 10) {
      break;
    }
    plan++;
  }

  if (task1) {
    plan = N - 1;
    while (1) {
      if (d[plan] + (N - plan - 1) * 10 > MIN) {
        if (d[plan] > 9) {
          MIN = d[plan] + (N - plan - 1) * 10;
          if (MIN >= (N - 1) * 10) {
            task2 = true;
            break;
          }
        }
      }
      if (MIN < (N - plan) * 10) {
        break;
      }
      plan--;
    }
  }

  if (task2) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main(void) {
  int N;
  int MAX = 0;
  int MIN = 0;
  bool task1 = false;
  bool task2 = false;
  static int d[300000];
  static int should[300000];

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

  int plan = 0;

  while (1) {
    if (d[plan] + (plan * 10) > MAX) {
      if (d[plan] > 9) {
        MAX = d[plan] + (plan * 10);
        if (MAX >= (N - 1) * 10) {
          task1 = true;
          break;
        }
      }
    }
    if (MAX < (plan + 1) * 10) {
      break;
    }
  }

  if (task1) {
    while (1) {
      plan = N - 1;
      if (d[plan] + (N - plan - 1) * 10 > MIN) {
        if (d[plan] > 9) {
          MIN = d[plan] + (N - plan - 1) * 10;
          if (MIN >= (N - 1) * 10) {
            task2 = true;
            break;
          }
        }
      }
      if (MIN < (plan + 1) * 10) {
        break;
      }
    }
  }

  if (task2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  int d[n];
  rep(i, n) cin >> d[i];
  int a = 10;
  rep(i, n) {
    a -= 10;
    if (a < 0) {
      cout << "no" << endl;
      return 0;
    }
    a = max(a, d[i]);
  }
  a = 10;
  reverse(d, d + n);
  rep(i, n) {
    a -= 10;
    if (a < 0) {
      cout << "no" << endl;
      return 0;
    }
    a = max(a, d[i]);
  }
  cout << "yes" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, count = 0, c, ans = 0;
  int d[300100] = {};
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> d[i];
  for (int i = 0; i < n - 1; i++) {
    if (d[0] < 10 || d[n - 1] < 10) {
      ans = 1;
      break;
    }
    if (d[i] >= 10) {
      count = 0;
      for (int j = 1; j <= d[i] / 10; j++)
        if (d[i + j] >= 10)
          count++;
    }
    if (count == 0) {
      ans = 1;
      break;
    }
  }
  if (ans != 1) {
    reverse(d, d + n);
    for (int i = 0; i < n - 1; i++) {
      if (d[i] >= 10) {
        count = 0;
        for (int j = 1; j <= d[i] / 10; j++)
          if (d[i + j] >= 10)
            count++;
      }
      if (count == 0) {
        ans = 1;
        break;
      }
    }
  }
  if (ans == 1)
    cout << "no" << endl;
  else
    cout << "yes" << endl;
  return 0;
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

const int lim = 300000;
bool jud[lim];
int dis[lim];

int main() {
  for (int i = 0; i < lim; i++) {
    jud[i] = false;
  }

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    dis[i] = d;
  }

  int count = 0;
  jud[0] = true;
  bool ans = false;
  while (jud[count] && count < n) {
    if (count == n - 1) {
      ans = true;
      break;
    }
    int jump;
    if (count + dis[count] / 10 >= lim) {
      jump = lim - 1;
    } else {
      jump = count + dis[count] / 10;
    }
    for (int i = jump; !jud[i]; i--) {
      jud[i] = true;
    }
    count++;
  }

  if (ans) {
    for (int i = 0; i < lim; i++) {
      jud[i] = false;
    }
    jud[n - 1] = true;
    ans = false;
    while (jud[count] && count <= n) {
      if (count == 0) {
        ans = true;
        break;
      }
      /*for(int i=1;i<=dis[count]/10&&count-i>=0;i++){
          jud[count-i] = true;
      }
      count--;*/
      int jump;
      if (count - dis[count] / 10 < 0) {
        jump = 0;
      } else {
        jump = count - dis[count] / 10;
      }
      for (int i = jump; !jud[i]; i++) {
        jud[i] = true;
      }
      count--;
    }
  }

  if (ans) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

const int lim = 300000;
bool jud[lim];
int dis[lim];

int main() {
  for (int i = 0; i < lim; i++) {
    jud[i] = false;
  }

  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    dis[i] = d;
  }

  int count = 0;
  jud[0] = true;
  bool ans = false;
  while (jud[count] && count < n) {
    if (count == n - 1) {
      ans = true;
      break;
    }
    for (int i = 1; i <= dis[count] / 10 && count + i < lim; i++) {
      jud[count + i] = true;
    }
    count++;
  }

  if (ans) {
    for (int i = 0; i < lim; i++) {
      jud[i] = false;
    }
    jud[n - 1] = true;
    ans = false;
    while (jud[count] && count <= n) {
      if (count == 0) {
        ans = true;
        break;
      }
      for (int i = 1; i <= dis[count] / 10 && count - i >= 0; i++) {
        jud[count - i] = true;
      }
      count--;
    }
  }

  if (ans) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }

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

#include <algorithm>
#include <iostream>
using namespace std;
int main() {

  int n, a[300000] = {}, r1 = 0, r2 = 0, can = 0;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    int how = a[i] / 10;
    can = max(can, i + how);
    if (can >= n - 1) {
      r1 = 1;
      break;
    }
    if (can == i)
      break;
  }
  if (r1 == 0) {
    cout << "no" << endl;
    return 0;
  }
  can = 0;
  reverse(a, a + n);
  for (int i = 0; i < n; i++) {
    int how = a[i] / 10;
    can = max(can, i + how);
    if (can >= n - 1) {
      r2 = 1;
      break;
    }
    if (can == i)
      break;
  }
  if (r2 == 0) {
    cout << "no" << endl;
    return 0;
  }
  cout << "yes" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {

  int n, a[300000] = {}, dp[300000] = {1}, r1 = 0, r2 = 0;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (dp[i] == 0)
      continue;
    int how = a[i] / 10;
    for (int j = 0; j < how; j++)
      if (i + j + 1 < n)
        dp[i + j + 1] = 1;
    if (dp[n - 1] == 1) {
      r1 = 1;
      break;
    }
  }
  if (r1 == 0) {
    cout << "no" << endl;
    return 0;
  }
  reverse(a, a + n);
  int dp2[300000] = {1};
  for (int i = 0; i < n; i++) {
    if (dp2[i] == 0)
      continue;
    int how = a[i] / 10;
    for (int j = 0; j < how; j++)
      if (i + j + 1 < n)
        dp2[i + j + 1] = 1;
    if (dp2[n - 1] == 1) {
      r2 = 1;
      break;
    }
  }
  if (r2 == 0) {
    cout << "no" << endl;
    return 0;
  }
  cout << "yes" << endl;
  return 0;
}
Problem p00357 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {

  int n, t[300010], r = 1;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> t[i];
  int le = t[0];
  for (int i = 1; i < n; i++) {
    le -= 10;
    if (le < 0)
      r = 0;
    le = max(le, t[i]);
  }

  reverse(t, t + n);

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

  cout << (r ? "yes" : "no") << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {

  int n, t[100000], r = 1;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> t[i];
  int le = t[0];
  for (int i = 1; i < n; i++) {
    le -= 10;
    if (le < 0)
      r = 0;
    le = max(le, t[i]);
  }

  reverse(t, t + n);

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

  cout << (r ? "yes" : "no") << endl;
  return 0;
}
Problem p00358 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int H, N;
int ngmask[10000];
int dp[10000][1 << 4];

int rec(int idx, int upbit) {
  if (idx == H)
    return (0);
  if (~dp[idx][upbit])
    return (dp[idx][upbit]);
  int ret = rec(idx + 1, ngmask[idx]);
  for (int i = 0; i < 3; i++) {
    if ((upbit >> i) & 3)
      continue;
    if ((ngmask[idx] >> i) & 3)
      continue;
    ret = max(ret, rec(idx + 1, (3 << i) | ngmask[idx]) + 1);
  }
  if (ngmask[idx] == 0 && upbit == 0) {
    ret = max(ret, rec(idx + 1, (1 << 4) - 1) + 2);
  }
  return (dp[idx][upbit] = ret);
}

int main() {
  cin >> H >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    ngmask[y] |= 1 << x;
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(1, ngmask[0]) << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int H, N;
int ngmask[1000];
int dp[1000][1 << 4];

int rec(int idx, int upbit) {
  if (idx == H)
    return (0);
  if (~dp[idx][upbit])
    return (dp[idx][upbit]);
  int ret = rec(idx + 1, ngmask[idx]);
  for (int i = 0; i < 3; i++) {
    if ((upbit >> i) & 3)
      continue;
    if ((ngmask[idx] >> i) & 3)
      continue;
    ret = max(ret, rec(idx + 1, (3 << i) | ngmask[idx]) + 1);
  }
  if (ngmask[idx] == 0 && upbit == 0) {
    ret = max(ret, rec(idx + 1, (1 << 4) - 1) + 2);
  }
  return (dp[idx][upbit] = ret);
}

int main() {
  cin >> H >> N;
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    ngmask[y] |= 1 << x;
  }
  memset(dp, -1, sizeof(dp));
  cout << rec(1, ngmask[0]) << endl;
}