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

#include <iostream>
using namespace std;

int main() {
  int a, b, N, s[1010] = {0}, f[1010] = {0}, hantei = 0;
  cin >> a >> b;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s[i] >> f[i];
    if (s[i] <= a && b <= f[i]) {
      hantei = 1;
    } else if (a <= s[i] && s[i] < b) {
      hantei = 1;
    } else if (a < f[i] && f[i] <= b) {
      hantei = 1;
    } else if (a < s[i] && f[i] < b) {
      hantei = 1;
    }
  }
  cout << hantei << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, N, s[120] = {0}, f[120] = {0}, hantei = 0;
  cin >> a >> b;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s[i] >> f[i];
    for (int j = s[i]; i <= f[i]; j++) {
      if (j == a || j == b) {
        hantei = 1;
      }
    }
    for (int j = a; i <= b; j++) {
      if (j == s[i] || j == f[i]) {
        hantei = 1;
      }
    }
  }
  cout << hantei << endl;
  return 0;
}
Problem p00355 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  bool res[1001] = {};
  int a, b, N;
  bool ans = false;

  cin >> a >> b;
  for (int i = a; i < b; i++)
    res[i] = true;

  cin >> N;
  for (int i = 0; i < N; i++) {
    int s, f;
    cin >> s >> f;
    for (int j = s; j < f; j++) {
      if (res[j])
        ans = true;
    }
  }

  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  bool res[1001];
  int a, b, N;
  bool ans = false;

  cin >> a >> b;
  for (int i = a; i < b; a++)
    res[i] = true;

  cin >> N;
  for (int i = 0; i < N; i++) {
    int s, f;
    cin >> s >> f;
    for (int j = s; j < f; j++) {
      if (res[j])
        ans = true;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

vi a(10000);
int n, l, r;

int main() {
  cin >> l >> r >> n;
  for (int i = 0; i < n; i++) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j < R; j++)
      a[j] = 1;
  }
  for (int i = l; i < r; i++) {
    if (a[i]) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

vi a(10000);
int n, l, r;

int main() {
  cin >> l >> r >> n;
  for (int i = 0; i < n; i++) {
    int L, R;
    cin >> L >> R;
    for (int j = L; j < R; j++)
      a[j] = 1;
  }
  for (int i = l; i < r; i++) {
    if (a[i]) {
      cout << 1 << endl;
      return 1;
    }
  }
  cout << 0 << endl;
}
Problem p00356 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int gcd(int x, int y) {
  if (y == 0) {
    return x;
  }

  return gcd(y, x % y);
}

int main() {
  int x, y;
  cin >> x >> y;

  int ans = x + y + 1 - gcd(x, y);
  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  double x, y;
  cin >> x >> y;
  double wire = y / (x * 2);

  int ans = x * 2 + y + 2;

  for (int i = 0; i <= x * 2; i + 2) {
    for (int j = 0; j <= y; j++) {
      if (wire * i == j) {
        ans--;
      }
    }
  }
  cout << ans << endl;

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

#include <iostream>
using namespace std;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  int x, y;
  cin >> x >> y;
  int GCD = gcd(x, y);
  cout << x + y - GCD + 1 << endl;

  return 0;
}


Error: -8

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int a, int b) {
  if (b == 0)
    return 0;
  return gcd(b, a % b);
}

int main() {
  int x, y;
  cin >> x >> y;
  int GCD = gcd(x, y);
  cout << x / GCD + y / GCD - GCD - 1 << endl;

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

#include <bits/stdc++.h>
using namespace std;
int N;
int d[1000000];
string checkprev() {
  int canhop = 1;
  for (int i = N - 1; i > 0; i--) {
    canhop--;
    canhop = max(canhop, d[i] / 10);
    if (canhop == 0)
      return "no";
  }
  return "yes";
}
string checkfront() {
  int canhop = 1;
  for (int i = 0; i < N; i++) {
    canhop--;
    canhop = max(canhop, d[i] / 10);
    if (canhop == 0)
      return "no";
  }
  return checkprev();
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  cout << checkfront() << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int N;
int d[1000000];
string checkprev() {
  int canhop = 0;
  for (int i = N - 1; i > 0; i++) {
    canhop = max(canhop, d[i] / 10);
    if (canhop == 0)
      return "no";
  }
  return "yes";
}
string checkfront() {
  int canhop = 0;
  for (int i = 0; i < N; i++) {
    canhop = max(canhop, d[i] / 10);
    if (canhop == 0)
      return "no";
  }
  return checkprev();
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> d[i];
  }
  cout << checkfront() << endl;
  return 0;
}
Problem p00357 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
using namespace std;
int a[300000];
int main() {
  long int N;
  bool flag = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i - 1];
  }
  if (a[0] >= 10 && a[N - 1] >= 10) {
    for (int k = 1; k <= N - 2; k++) {
      if (a[k] < 10) {
        flag = 0;
        int yosi = 0;
        for (int o = 1;; o++) {
          if (a[k - o] >= (10 * o + 10)) {
            yosi++;
            break;
          }
          if ((k - o) == 0) {
            cout << "no" << endl;
            return 0;
          }
        }
        for (int u = 1;; u++) {
          if (a[k + u] >= (10 * u + 10)) {
            yosi++;
            break;
          }
          if ((k + u) == (N - 1)) {
            cout << "no" << endl;
            return 0;
          }
        }
        if (yosi == 2) {
          flag = 1;
        } else {
          cout << "no" << endl;
          return 0;
        }
      }
    }
    flag = 1;
  }

  if (flag == 0) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
int a[100000];
int main() {
  long int N;
  bool flag = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> a[i - 1];
  }
  if (a[0] >= 10 && a[N - 1] >= 10) {
    for (int k = 1; k <= N - 2; k++) {
      if (a[k] < 10) {
        flag = 0;
        int yosi = 0;
        for (int o = 1;; o++) {
          if (a[k - o] >= (10 * o + 10)) {
            yosi++;
            break;
          }
          if ((k - o) == 0) {
            cout << "no" << endl;
            return 0;
          }
        }
        for (int u = 1;; u++) {
          if (a[k + u] >= (10 * u + 10)) {
            yosi++;
            break;
          }
          if ((k + u) == (N - 1)) {
            cout << "no" << endl;
            return 0;
          }
        }
        if (yosi == 2) {
          flag = 1;
        } else {
          cout << "no" << endl;
          return 0;
        }
      }
    }
    flag = 1;
  }

  if (flag == 0) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }

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

//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <iostream>

using namespace std;

int n;
int d[300001] = {};

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
  }
  int d1 = 0;
  int flg = 0;
  for (int i = 0; i < n; ++i) {
    d1 = max(d1, 10 * i + d[i]);
    if (d1 < 10 * (i + 1))
      flg = 1;
  }
  d1 = 10 * (n - 1);
  for (int i = n - 1; i >= 0; --i) {
    d1 = min(d1, 10 * i - d[i]);
    if (d1 > 10 * (i - 1))
      flg = 1;
  }

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

Error: TLE

Fixed submission:

//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <algorithm>
#include <iostream>

using namespace std;

int n;
int d1[300001] = {};
int dp1[300001] = {};
int d2[300001] = {};
int dp2[300001] = {};

int calc1(int k) {
  if (dp1[k] >= 0)
    return dp1[k];
  dp1[k] = d1[k];
  for (int res = d1[k]; res > 0; res--) {
    if (k + res < n)
      dp1[k] = max(dp1[k], res + calc1(k + res));
  }
  return dp1[k];
}
int calc2(int k) {
  if (dp2[k] >= 0)
    return dp2[k];
  dp2[k] = d2[k];
  for (int res = d2[k]; res > 0; res--) {
    if (k + res < n)
      dp2[k] = max(dp2[k], res + calc2(k + res));
  }
  return dp2[k];
}
int main() {

  for (int i = 0; i < 300001; ++i) {
    dp1[i] = -1;
    dp2[i] = -1;
  }
  cin >> n;
  int t;
  for (int i = 0; i < n; ++i) {
    cin >> t;
    d1[i] = t / 10;
    d2[n - i - 1] = d1[i];
  }
  dp1[n - 1] = 0;
  dp2[n - 1] = 0;

  int flg = 0;
  if (calc1(0) >= n - 1)
    flg += 1;
  if (calc2(0) >= n - 1)
    flg += 1;
  if (flg == 2) {
    cout << "yes" << endl;
  } else {
    cout << "no" << endl;
  }
  return 0;
}
Problem p00357 (C++) — buggy submission, verdict: Runtime Error

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

int a[300001];
bool solve1(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) {
    if (i > p)
      return 0;
    p = max(p, i + (a[i] / 10));
  }
  return p >= n - 1;
}

bool solve2(int n) {
  int p = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (i < p)
      return 0;
    p = min(p, i - (a[i] / 10));
  }
  return p <= 0;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  bool x = solve1(n);
  bool y = solve2(n);
  if (x && y)
    printf("yes\\n");
  else
    printf("no\\n");
  return 0;
}


Error: 0

Fixed submission:

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

int a[100001];
bool solve1(int n) {
  int p = 0;
  for (int i = 0; i < n; i++) {
    if (i > p)
      return 0;
    p = max(p, i + (a[i] / 10));
  }
  return p >= n - 1;
}

bool solve2(int n) {
  int p = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (i < p)
      return 0;
    p = min(p, i - (a[i] / 10));
  }
  return p <= 0;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  bool x = solve1(n);
  bool y = solve2(n);
  if (x && y)
    printf("yes\\n");
  else
    printf("no\\n");
  return 0;
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int n;
int d[1000000];

string check2() {
  int nowpos = n - 1;
  int canhop = n - 1;
  int minhop = n - 1;

  for (int j = 0; j < 300000; j++) {
    canhop = nowpos - d[nowpos] / 10;
    minhop = canhop;
    if (canhop <= 0)
      return "yes";

    for (int i = nowpos; i >= canhop; i--) {
      if (i - d[i] / 10 < minhop) {
        nowpos = i;
        minhop = i - d[i] / 10;
      }
    }
  }
  return "no";
}

string check1() {
  int nowpos = 0;
  int canhop = 0;
  int maxhop = 0;

  for (int j = 0; j < 300000; j++) {
    canhop = d[nowpos] / 10 + nowpos;
    maxhop = canhop;
    if (canhop >= n - 1)
      return check2();

    for (int i = nowpos; i <= canhop; i++) {
      if (d[i] / 10 + i >= maxhop) {
        nowpos = i;
        maxhop = d[i] / 10 + i;
      }
    }
  }
  return "no";
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
    int sub = d[i] % 10;
    d[i] -= sub;
  }
  cout << check1() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int n;
int d[1000000];

string check2() {
  int nowpos = n - 1;
  int canhop = n - 1;
  int minhop = n - 1;

  while (true) {
    canhop = nowpos - d[nowpos] / 10;
    if (minhop <= 0)
      return "yes";

    for (int i = nowpos; i >= canhop; i--) {
      if (i - d[i] / 10 < canhop)
        nowpos = i;
      minhop = min(minhop, i - d[i] / 10);
    }

    if (minhop == canhop)
      return "no";
  }
}

string check1() {
  int nowpos = 0;
  int canhop = 0;
  int maxhop = 0;

  while (true) {
    canhop = d[nowpos] / 10 + nowpos;
    if (canhop >= n - 1)
      return check2();

    for (int i = nowpos; i <= canhop; i++) {
      if (d[i] / 10 + i > canhop)
        nowpos = i;
      maxhop = max(maxhop, d[i] / 10 + i);
    }

    if (maxhop == canhop)
      return "no";
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  cout << check1() << 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 jump[N];
  for (int i = 0; i < N; i++) {
    cin >> jump[i];
  }
  int jum_dis = 0;
  for (int i = 0; i < N - 1; i++) {
    jum_dis = max(jum_dis, jump[i]);
    if (jum_dis < 10) {
      cout << "no\\n";
      return 0;
    }
    jum_dis -= 10;
  }

  jum_dis = 0;
  for (int i = 0; i < N - 1; i++) {
    jum_dis = max(jum_dis, jump[N - i - 1]);
    if (jum_dis < 10) {
      cout << "no\\n";
      return 0;
    }
    jum_dis -= 10;
  }

  cout << "yes\\n";
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int N;
bool flag1 = false, flag2 = false;
void DFS_l_to_r(int *jums, int i) {
  if (flag1)
    return;
  if (i >= N - 1) {
    flag1 = true;
    return;
  }
  if (jums[i] < 10)
    return;
  else {
    for (int j = jums[i] / 10; 1 <= j; j--) {
      DFS_l_to_r(jums, i + j);
    }
  }
}

void DFS_r_to_l(int *jums, int i) {
  if (flag2)
    return;
  if (i <= 0) {
    flag2 = true;
    return;
  }
  if (jums[i] < 10)
    return;
  else {
    for (int j = jums[i] / 10; 1 <= j; j--) {
      DFS_r_to_l(jums, i - j);
    }
  }
}

int main() {
  cin >> N;
  int jums[N];
  for (int i = 0; i < N; i++) {
    cin >> jums[i];
  }
  DFS_l_to_r(jums, 0);
  DFS_r_to_l(jums, N - 1);
  if (flag1 && flag2)
    cout << "yes\\n";
  else
    cout << "no\\n";
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX

typedef long long ll;
typedef pair<int, int> ii;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  int maxi = 0;
  rep(i, n) cin >> d[i];
  rep(i, n) {
    if (maxi < i)
      continue;
    maxi = max(maxi, i + d[i] / 10);
  }

  if (maxi < n - 1) {
    cout << "no" << endl;
    return 0;
  }
  int mini = n - 1;
  for (int i = n - 1; i >= 0; --i) {
    if (i < mini)
      continue;
    mini = min(mini, i - d[i] / 10);
  }
  cout << (mini <= 0 ? "yes" : "no") << endl;
}

Error: TLE

Fixed submission:

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX

typedef long long ll;
typedef pair<int, int> ii;

int main() {
  int n;
  cin >> n;
  vector<bool> ok(n, false);
  vector<int> d(n);
  ok[0] = true;
  rep(i, n) {
    cin >> d[i];
    if (!ok[i])
      continue;
    rep(j, min(n - i, 1 + d[i] / 10)) ok[i + j] = true;
  }

  if (!ok[n - 1]) {
    cout << "no" << endl;
    return 0;
  }
  vector<bool> ok2(n, false);
  ok2[n - 1] = true;
  for (int i = n - 1; i >= 0; --i) {
    if (!ok2[i])
      continue;
    rep(j, min(i + 1, 1 + d[i] / 10)) ok2[i - j] = true;
  }
  cout << (ok2[0] ? "yes" : "no") << endl;
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#define lol(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

queue<int> Q;
int d[300010], n;

int p[300010];
bool Fcan() {
  lol(i, n) p[i] = max(1, i);
  while (!Q.empty())
    Q.pop();
  Q.push(0);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    // cout<<x<<" ";
    int a = max(0, x - d[x] / 10), b = a, t;
    while (p[a] != a)
      a = p[a];
    while (p[b] != b)
      t = p[b], p[b] = a, b = t;

    while (true) {
      if (a > x + d[x] / 10)
        break;
      if (a == n - 1)
        return true;
      Q.push(a);
      p[a] = a + 1;
      a = p[a + 1];
    }
  }
  return 0;
}

int main() {
  cin >> n;
  lol(i, n) {
    cin >> d[i];
    // d[i]=10;
  }
  bool ok = Fcan();
  lol(i, n / 2) swap(d[i], d[n - 1 - i]);
  ok &= Fcan();
  cout << (ok ? "yes" : "no") << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#define lol(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
set<int> st;
queue<int> Q;
int d[300010], n;

bool Fcan() {
  st.clear();
  while (!Q.empty())
    Q.pop();
  for (int i = 1; i < n; i++)
    st.insert(i);
  Q.push(0);
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    // cout<<x<<" ";
    if (x == n - 1) {
      return true;
    }
    set<int>::iterator it;
    it = lower_bound(st.begin(), st.end(), x - d[x] / 10);
    while (it != st.end()) {
      if (*it > x + d[x] / 10)
        break;
      Q.push(*it);
      it = st.erase(it);
    }
  }
  return 0;
}

int main() {
  cin >> n;
  lol(i, n) { cin >> d[i]; }
  bool ok = Fcan();
  lol(i, n / 2) swap(d[i], d[n - 1 - i]);
  ok &= Fcan();
  cout << (ok ? "yes" : "no") << endl;
  return 0;
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;
int n, m, a[300010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  m = 0;
  for (int i = 0; i <= m; i++) {
    m = max(a[i] / 10 + i, m);
    if (m >= n)
      goto heaven1;
  }
  cout << "no\\n";
  return 0;
heaven1:
  m = n - 1;
  for (int i = n - 1; i >= m; i--) {
    m = min(i - a[i] / 10, m);
    if (m <= 0)
      goto heaven2;
  }
  cout << "no\\n";
  return 0;
heaven2:
  cout << "yes\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int n, d[310000];
bool f1(int p) {
  if (p == n - 1)
    return true;
  for (int i = 0; i < d[p] / 10; i++) {
    if (f1(p + i + 1))
      return true;
  }
  return false;
}
bool f2(int p) {
  if (p == 0)
    return true;
  for (int i = 0; i < d[p] / 10; i++) {
    if (f2(p - i - 1))
      return true;
  }
  return false;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> d[i];
  if (f1(0) && f2(n - 1))
    cout << "yes\\n";
  else
    cout << "no\\n";
  return 0;
}
Problem p00357 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lpin(a, i, n)                                                          \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> a[i];                                                               \\
  }

int a[1000000], b[1000000], check;

void migi(int i, int n) {
  lp(x, n) {
    if (a[x] == 0)
      1;
    else {
      b[x] += 1;
      b[x + a[x]] -= 1;
    }
  }
  for (int x = 1; x < n; x++) {
    b[x] += b[x - 1];
  }
  lp(x, n) {
    if (b[x] > 0)
      1;
    else {
      check = 1;
      return;
    }
  }
  return;
}

int main() {
  int n;
  cin >> n;
  lp(i, n) {
    cin >> a[i];
    a[i] /= 10;
  }
  check = 0;
  migi(0, n);
  if (check == 0) {
    lp(j, 1000000) { b[j] = 0; }
    check = 0;
    reverse(a, a + n);
    migi(0, n);
    if (check == 0) {
      cout << "yes" << endl;
    } else
      cout << "no" << endl;
  } else
    cout << "no" << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
#define lpin(a, i, n)                                                          \\
  for (int i = 0; i < n; i++) {                                                \\
    cin >> a[i];                                                               \\
  }

int a[1000000], b[1000000], check;

void migi(int i, int n) {
  if (check == 1)
    return;
  if (i == n - 1) {
    check = 1;
    return;
  }
  if (b[i] == 1)
    return;
  b[i] = 1;
  for (int x = 1; x <= a[i]; x++) {
    if (a[i] == 0)
      return;
    migi(i + x, n);
  }
}

int main() {
  int n;
  cin >> n;
  lp(i, n) {
    cin >> a[i];
    a[i] /= 10;
  }
  check = 0;
  migi(0, n);
  if (check == 1) {
    lp(j, 1000000) { b[j] = 0; }
    check = 0;
    reverse(a, a + n);
    migi(0, n);
    if (check == 1) {
      cout << "yes" << endl;
    } else
      cout << "no" << endl;
  } else
    cout << "no" << endl;

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

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

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

  int a[300500];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] = a[i] / 10;
  }
  int mx = 0;
  for (int i = 0; i <= mx; i++) {
    mx = max(mx, a[i] + i);
    if (mx > n) {
      break;
    }
  }
  bool j = true;
  if (n - 1 > mx) {
    j = false;
  }

  reverse(a, a + n);
  mx = 0;
  for (int i = 0; i <= mx; i++) {
    mx = max(mx, a[i] + i);
    if (mx > n) {
      break;
    }
  }
  if (n - 1 > mx) {
    j = false;
  }

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

  return 0;
}


Error: 0

Fixed submission:

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

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

  int a[300500];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] = a[i] / 10;
  }
  int mx = 0;
  for (int i = 0; i <= mx; i++) {
    mx = max(mx, a[i] + i);
  }
  bool j = true;
  if (n - 1 > mx) {
    j = false;
  }

  reverse(a, a + n);
  mx = 0;
  for (int i = 0; i <= mx; i++) {
    mx = max(mx, a[i] + i);
  }
  if (n - 1 > mx) {
    j = false;
  }

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

  return 0;
}