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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n, l;
  cin >> n >> l;
  int a[n];
  REP(i, n) { cin >> a[i]; }
  typedef pair<int, int> pii;
  priority_queue<pii, vector<pii>, greater<pii>> Q;
  REP(i, n) {
    bool f = 1;
    if (i && a[i - 1] >= a[i])
      f = 0;
    if (i < n - 1 && a[i + 1] >= a[i])
      f = 0;
    if (f) {
      Q.push(pii(l - a[i], i));
    }
  }
  int ans;
  while (!Q.empty()) {
    pii p = Q.top();
    Q.pop();
    int t = p.first;
    int s = p.second;
    // cout << t << " " << s << endl;
    ans = t;
    a[s] = 0;
    if (s >= 2 && a[s - 1] > a[s - 2])
      Q.push(pii(t + l - a[s - 1], s - 1));
    if (s <= n - 3 && a[s + 1] > a[s + 2])
      Q.push(pii(t + l - a[s + 1], s + 1));
    if (s == 1 && a[0])
      Q.push(pii(t + l - a[0], 0));
    if (s == n - 2 && a[n - 1])
      Q.push(pii(t + l - a[n - 1], n - 1));
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n, l;
  cin >> n >> l;
  int a[n];
  REP(i, n) { cin >> a[i]; }
  int t = 0;
  int ans = 0;
  while (1) {
    int tt = INF;
    bool hoge[n];
    memset(hoge, 0, sizeof(hoge));
    REP(i, n) {
      bool f = 1;
      if (i && a[i - 1] >= a[i])
        f = 0;
      if (i < n - 1 && a[i + 1] >= a[i])
        f = 0;
      if (f) {
        hoge[i] = 1;
        tt = min(tt, l - a[i]);
      }
    }
    if (tt == INF)
      break;

    REP(i, n) {
      if (hoge[i]) {
        a[i] += tt;
        if (a[i] == l)
          a[i] = 0;
      }
    }
    // REP(i, n) cout << a[i] << " ";
    // cout << endl;
    ans += tt;
  }
  cout << ans << endl;
}
Problem p00474 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
long long qw[100000], dp[100000], a, b;
long long solve(long long k) {
  if (dp[k] > 0)
    return dp[k];
  if ((k == 0 && qw[k] > qw[k + 1]) || (k == a - 1 && qw[k] > qw[k - 1]) ||
      (qw[k] > qw[k - 1] && qw[k] > qw[k + 1])) {
    return dp[k] = b - qw[k];
  }
  if (k == 0)
    return dp[k] = solve(1) + b - qw[k];
  if (k == a - 1)
    return dp[k] = solve(a - 2) + b - qw[k];
  if (qw[k] < qw[k - 1])
    dp[k] = max(dp[k], solve(k - 1) + b - qw[k]);
  if (qw[k] < qw[k + 1])
    dp[k] = max(dp[k], solve(k + 1) + b - qw[k]);
}
int main() {
  scanf("%lld %lld", &a, &b);
  for (int i = 0; i < a; i++) {
    scanf("%lld", &qw[i]);
  }
  for (int i = 0; i < a; i++) {
    int ru = solve(i);
  }
  printf("%d\\n", *max_element(dp, dp + a));
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
long long qw[100000], dp[100000], a, b;
long long solve(long long k) {
  if (dp[k] > 0)
    return dp[k];
  if ((k == 0 && qw[k] > qw[k + 1]) || (k == a - 1 && qw[k] > qw[k - 1]) ||
      (qw[k] > qw[k - 1] && qw[k] > qw[k + 1])) {
    return dp[k] = b - qw[k];
  }
  if (k == 0)
    return dp[k] = solve(1) + b - qw[k];
  if (k == a - 1)
    return dp[k] = solve(a - 2) + b - qw[k];
  if (qw[k] < qw[k - 1])
    dp[k] = max(dp[k], solve(k - 1) + b - qw[k]);
  if (qw[k] < qw[k + 1])
    dp[k] = max(dp[k], solve(k + 1) + b - qw[k]);
}
int main() {
  scanf("%lld %lld", &a, &b);
  for (int i = 0; i < a; i++) {
    scanf("%lld", qw[i]);
  }
  for (int i = 0; i < a; i++)
    int ru = solve(i);
  printf("%d\\n", *max_element(dp, dp + a));
  return 0;
}
Problem p00475 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <map>
#include <stdio.h>
#include <vector>
#define INF 1000000
using namespace std;
typedef pair<int, int> P;
P pt[100000];
P xs;

int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }

P update(P r, int x) { return P(min(r.first, x), max(r.second, x)); }

bool solve(int n, int D) {
  int i;
  vector<int> ry;
  P yr[2] = {P(INF, -INF), P(INF, -INF)};
  for (i = 0; i < n; i++) {
    int x = pt[i].first;
    int y = pt[i].second;
    if (x > xs.first + D && x < xs.second - D)
      return false;
    else if (x > xs.first + D)
      yr[1] = update(yr[1], y);
    else if (x < xs.second - D)
      yr[0] = update(yr[0], y);
    else
      ry.push_back(y);
  }
  sort(ry.begin(), ry.end());
  P yrt[2] = {yr[0], yr[1]};
  int p = 0;
  while (p < ry.size() && ry[p] <= yrt[0].first + D)
    yrt[0] = update(yrt[0], ry[p++]);
  for (; p < ry.size(); p++)
    yrt[1] = update(yrt[1], ry[p]);
  if (yrt[0].second - yrt[0].first <= D && yrt[1].second - yrt[1].first <= D)
    return true;
  yrt[0] = yr[0];
  yrt[1] = yr[1];
  p = 0;
  while (p < ry.size() && ry[p] <= yrt[1].first + D)
    yrt[1] = update(yrt[1], ry[p++]);
  for (; p < ry.size(); p++)
    yrt[0] = update(yrt[0], ry[p]);
  if (yrt[0].second - yrt[0].first <= D && yrt[1].second - yrt[1].first <= D)
    return true;
  return false;
}

int main() {
  int n, i;
  scanf("%d", &n);
  xs = P(INF, -INF);
  for (i = 0; i < n; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    int a = x + y;
    int b = x - y;
    pt[i] = P(a, b);
    xs = update(xs, a);
  }
  int l = 0, r = INF;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (solve(n, mid))
      r = mid;
    else
      l = mid;
  }
  printf("%d\\n", r);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int x[100000];
int y[100000];
bool used[100000];
bool c[100000];
int n;
int min(int a, int b) { return a < b ? a : b; }
int abs(int a) { return a >= 0 ? a : -a; }
int dis(int a, int b) { return abs(x[a] - x[b]) + abs(y[a] - y[b]); }
void dfs(int v, int m, bool color) {
  used[v] = true;
  c[v] = color;
  for (int i = 0; i < n; i++) {
    if (!used[i] && dis(i, v) > m)
      dfs(i, m, !color);
  }
}
bool check(int m) {
  int i, j;
  for (i = 0; i < n; i++)
    used[i] = false;
  for (i = 0; i < n; i++) {
    if (!used[i])
      dfs(i, m, true);
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      if (!(c[i] ^ c[j]) && dis(i, j) > m)
        break;
    }
    if (j != n)
      break;
  }
  if (i == n)
    return true;
  return false;
}
int main() {
  int i;
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d %d", &x[i], &y[i]);
  int l = 0, r = 300000, mid;
  int ans = 300000;
  for (i = 0; i < 20; i++) {
    mid = (l + r) / 2;
    if (check(mid)) {
      ans = min(ans, mid);
      r = mid;
    } else
      l = mid;
  }
  printf("%d\\n", ans);
}
Problem p00476 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int N, H, d[100000], h[100000], sum[100000];
signed main() {
  cin >> N >> H;
  rep(i, N - 1) cin >> d[i] >> h[i];

  sum[0] = H;
  rep(i, N - 1) sum[i + 1] = sum[i] - d[i];
  int D = 0;

  int ans = 0, idx = 0;
  deque<int> deq;
  rep(i, N - 1) {

    if (H - (sum[i] - D) <= h[i]) {
      deq.clear();
      idx = i;
    } else {
      while (deq.size() && h[deq.back()] <= h[i])
        deq.pop_back();
      deq.push_back(i);
    }

    while (sum[i + 1] - D <= 0) {
      if (deq.size() && H - (sum[idx] - D) <= h[deq.front()]) {
        int j = deq.front();
        int t = min((H - (sum[j] - D)) / h[j], (D - sum[i + 1]) / h[j] + 1);
        ans += t;
        D -= t * h[j];
      } else {
        ans++;
        D -= H - (sum[idx] - D);
      }
      while (deq.size() && H - (sum[deq.front()] - D) < h[deq.front()]) {
        idx = deq.front();
        deq.pop_front();
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int N, H, d[100000], h[100000], sum[100000];
signed main() {
  cin >> N >> H;
  rep(i, N - 1) cin >> d[i] >> h[i];

  sum[0] = H;
  rep(i, N - 1) sum[i + 1] = sum[i] - d[i];
  int D = 0;

  int ans = 0, idx = 0;
  deque<int> deq;
  rep(i, N - 1) {

    if (H - (sum[i] - D) <= h[i]) {
      deq.clear();
      idx = i;
    } else {
      while (deq.size() && h[deq.back()] <= h[i])
        deq.pop_back();
      deq.push_back(i);
    }

    while (sum[i + 1] - D <= 0) {
      if (deq.size() && H - (sum[idx] - D) <= h[deq.front()]) {
        int j = deq.front();
        int t = min((H - (sum[j] - D)) / h[j], (D - sum[i + 1]) / h[j] + 1);
        ans += t;
        D -= t * h[j];
        while (deq.size() && H - (sum[deq.front()] - D) < h[j]) {
          deq.pop_front();
          idx = j;
        }
      } else {
        ans++;
        D -= H - (sum[idx] - D);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p00476 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;
typedef pair<ll, pair<ll, ll>> pp;
pp mm[100001];
ll d[100001];

int main() {
  ll n, h;
  ll ans = 0;
  cin >> n >> h;
  ll di, hi, ch = h;
  for (int i = 0; i < n - 1; ++i) {
    cin >> di >> hi;
    mm[i].first = ch + hi <= h || ch < 0 ? hi : h - ch;
    mm[i].second.first = i;
    mm[i].second.second = ch;
    d[i] = di;
    ch -= di;
  }
  int l = 0;
  for (int i = 0; i < n; ++i) {
    ch = mm[i].second.second;
    if (ch <= 0) {
      pp t = *max_element(mm + l, mm + i);
      hi = t.first;
      int ch2 = t.second.second;
      i = t.second.first;
      l = i;
      int div;
      if (-ch / hi + 1 > (h - ch2) / hi) {
        div = (h - ch2) / hi;
        ans += div;
        ch = ch2 + hi * div;
      } else {
        div = -ch / hi + 1;
        ans += div;
        ch = min(h, ch2 + hi * div);
      }
    }
    hi = mm[i].first;
    mm[i].first = ch + hi > h ? h - ch : hi;
    mm[i].second.second = ch;
    mm[i + 1].second.second = ch - d[i];
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

typedef pair<int, pair<int, int>> pp;
pp mm[100001];
int d[100001];

int main() {
  int n, h;
  long long ans = 0;
  cin >> n >> h;
  int di, hi, ch = h;
  for (int i = 0; i < n - 1; ++i) {
    cin >> di >> hi;
    mm[i].first = ch + hi <= h || ch < 0 ? hi : h - ch;
    mm[i].second.first = i;
    mm[i].second.second = ch;
    d[i] = di;
    ch -= di;
  }
  int l = 0;
  for (int i = 0; i < n; ++i) {
    ch = mm[i].second.second;
    if (ch <= 0) {
      pp t = *max_element(mm + l, mm + i);
      hi = t.first;
      int ch2 = t.second.second;
      i = t.second.first;
      l = i;
      int div;
      if (-ch / hi + 1 > (h - ch2) / hi) {
        div = (h - ch2) / hi;
        ans += div;
        ch = ch2 + hi * div;
        mm[i].second.second = ch;
        mm[i].first = ch + hi <= h ? hi : h - ch;
        --i;
        continue;
      }
      div = -ch / hi + 1;
      ans += div;
      ch = min(h, ch2 + hi * div);
    }
    hi = mm[i].first;
    mm[i].first = ch + hi > h ? h - ch : hi;
    mm[i].second.second = ch;
    mm[i + 1].second.second = ch - d[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p00477 (C++) — buggy submission, verdict: Time Limit Exceeded

/**********************************************

1.
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@12:02

 **********************************************/
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main(void) {

  while (1) {
    int minute = 0;
    int total = 0;

    for (int i = 0; i < 4; i++) {
      cin >> minute;
      total = total + minute;
    }

    if (minute == NULL)
      break;

    int x = total / 60;
    int y = total % 60;

    cout << x << endl;
    cout << y << endl;
  }
}

Error: TLE

Fixed submission:

/**********************************************

1.
2.炭田高輝
3.sumita.takaki@gmail.com

last updated: 2013-07-10@12:01

 **********************************************/
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main(void) {

  while (1) {
    int minute = 0;
    int total = 0;

    for (int i = 0; i < 4; i++) {
      cin >> minute;
      total = total + minute;
    }

    int x = total / 60;
    int y = total % 60;

    cout << x << endl;
    cout << y << endl;
  }
}
Problem p00477 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define reep(n1, n2, n3) for (int n1 = n3; n1 < n2; n1++)
#define rep(n1, n2) reep(n1, n2, 0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vp;
typedef pair<int, int> pi;
typedef pair<int, pair<int, int>> pii;
typedef vector<string> vs;
const double PI = acos(-1.0);
int main() {
  int n = 0;
  rep(i, 4) {
    int a;
    cin >> a;
    n += a;
  }
  cout << n / 60 << endl;
  cout << n % 60 << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define reep(n1, n2, n3) for (int n1 = n3; n1 < n2; n1++)
#define rep(n1, n2) reep(n1, n2, 0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vp;
typedef pair<int, int> pi;
typedef pair<int, pair<int, int>> pii;
typedef vector<string> vs;
const double PI = acos(-1.0);
int c[] = {500, 100, 50, 10, 5, 1};
int main() {
  int n = 0;
  rep(i, 4) {
    int a;
    cin >> a;
    n += a;
  }
  cout << n / 60 << endl << n % 60 << endl;
}
Problem p00477 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main() {
  int i1[2] = {0};

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

  printf("%d\\n", i1[1] / 60);
  printf("%d\\n", i1[1] % 60);
}

Error: WA

Fixed submission:

#include <cstring>
#include <stdio.h>

int main() {
  int i1[2] = {0};
  int ansers[5] = {0};
  int total = 1;

  for (int n = 0; n < 6; n++) {
    scanf("%d", &total);
    if (total == 0) {
      for (int x = 0; x < n; x++)
        printf("%d\\n", ansers[x]);
      return 0;
    }
    memset(i1, 0, sizeof(i1));

    for (int n = 0; n < 9; n++) {
      scanf("%d", &i1[1]);
      i1[0] += i1[1];
    }
    ansers[n] = total - i1[0];
  }
}
Problem p00478 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string A, S, T;
  int P = 0;
  int n;
  cin >> A;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S;
    T = S + S;
    for (int j = 0; j < 10; j++) {
      if (T.substr(j, A.length()) == A) {
        P++;
        break;
      }
    }
  }
  cout << P << endl;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  string A, S, T;
  int P = 0;
  int n;
  cin >> A;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> S;
    T = S + S;
    for (int j = 0; j < n; j++) {
      if (T.substr(j, A.length()) == A) {
        P++;
        break;
      }
    }
  }
  cout << P << endl;
  return 0;
}
Problem p00478 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  char tar[11];
  char ringc[100][21];
  int ringi;
  int result = 0;

  cin >> tar;
  cin >> ringi;

  for (int a = 0; a < ringi; a++) {
    cin >> ringc[a];
  }
  for (int a = 0; a < ringi; a++) {
    for (int b = 0; b < 10; b++) {
      ringc[a][b + 10] = ringc[a][b];
    }
    ringc[a][20] = 0;
  }

  for (int a = 0; a < ringi; a++) {
    for (int b = 0; b < 21; b++) {
      if (ringc[a][b] == tar[0]) {
        for (int c = 1;; c++) {
          if (tar[c] == 0) {
            result++;
            goto x;
          } else if (ringc[a][b + c] != tar[c]) {
            goto y;
          }
        }
      }
    y:;
    }
  x:;
  }

  cout << result << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  char tar[11];
  char ringc[100][11];
  int ringi;
  int result = 0;

  cin >> tar;
  cin >> ringi;

  for (int a = 0; a < ringi; a++) {
    cin >> ringc[a];
  }
  for (int a = 0; a < ringi; a++) {
    for (int b = 0; b < 10; b++) {
      if (ringc[a][b] == tar[0]) {
        for (int c = b + 1; c != b; c++) {
          if (c >= 10) {
            c = 0;
            b -= 10;
          }
          if (tar[c - b] == 0) {
            result++;
            goto e;
          } else {
            if (ringc[a][c] != tar[c - b]) {
              cout << endl;
              break;
            }
          }
        }
      }
    }
  e:;
  }

  cout << result << endl;

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

#include <iostream>
char str[11], ch[11];
int n, i;
using namespace std;
bool check(int a, int b) {
  if (b == 10)
    b -= 10;
  if (ch[a] == str[b] && ch[a] != '\\0')
    check(a + 1, b + 1);
  else if (ch[a] == '\\0')
    return true;
  else
    return false;
}
int main() {
  int j, count;
  while (cin >> ch) {
    count = 0;
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> str;
      for (j = 0; j < 10; j++) {
        if (ch[0] == str[j])
          if (check(0, j)) {
            count++;
            break;
          }
      }
    }
    cout << count << endl;
    for (i = 0; i < 10; i++) {
      ch[i] = '\\0';
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#include <string.h>

int main() {
  int i, tortal = 0, n, nn, tmpi, strlong, cnt = 0;
  char string[11], changestr[11];
  while (fscanf(stdin, "%s", changestr) != 0) {
    strlong = strlen(changestr);
    fscanf(stdin, "%d", &n);
    for (nn = 0; nn < n; nn++) {
      fscanf(stdin, "%s", string);
      for (i = 0; i < 11; i++) {
        if (string[i] == changestr[cnt]) {
          tmpi = i + 1;
          cnt += 1;
          if (cnt == strlong) {
            tortal += 1;
            break;
          }
          if (tmpi == 10) {
            tmpi = 0;
          }
          for (tmpi; tmpi < (i + strlong); tmpi++) {

            if (string[tmpi] != changestr[cnt])
              break;
            cnt += 1;
            if (strlong == cnt) {
              tortal += 1;
              break;
            }
            if (tmpi == 9)
              tmpi = -1;
          }
        }
        cnt = 0;
      }
      cnt = 0;
    }
  }
  fprintf(stdout, "%d\\n", tortal);
  return 0;
}
Problem p00478 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;
#include <string.h>
#include <string>
int main() {
  string v, s;
  int i, j = 0, n, g = 0;
  cin >> v >> n;
  for (i = 0; i < n; i++) {
    cin >> s;
    s = (s + s + s);
    if (s.find(v) != -1) {
      g++;
    }
  }
  printf("%d\\n", g);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;
#include <string.h>
int main() {
  char v[30], s[30];
  int i, j, n, g = 0, c, m, l;
  scanf("%s%d", v, &n);
  l = strlen(v);
  for (i = 0; i < n; i++) {
    m = 0;
    scanf("%s", s);
    c = strlen(s);
    for (j = 0; j < c; j++) {
      if (j == 0) {
        if (v[m] == s[c - 1]) {
          m++;
          if (m == l) {
            g++;
            break;
          }
        }
      }
      if (v[m] == s[j]) {
        m++;
        if (m == l) {
          g++;
          break;
        }
      } else {
        j -= m;
        m = 0;
      }
      if (j == c - 1) {
        if (v[m] == s[0]) {
          m++;
          if (m == l) {
            g++;
            break;
          }
        }
      }
    }
  }
  printf("%d\\n", g);
  return 0;
}
Problem p00478 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>

int main() {
  int a, res = 0;
  char x[20], y[40], z[20];
  scanf("%s", &x);
  scanf("%d", &a);
  for (int i = 0; i < a; i++) {
    scanf("%s", &y);
    strcpy(z, y);
    strcat(y, z);
    if (strstr(y, x)) {
      res++;
    }
  }
  printf("%d\\n", res);
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>

int main() {
  int a, res = 0;
  char x[20], y[40];
  scanf("%s", &x);
  scanf("%d", &a);
  for (int i = 0; i < a; i++) {
    scanf("%s", &y);
    strcat(y, y);
    if (strstr(y, x)) {
      res++;
    }
  }
  printf("%d\\n", res);
  return 0;
}
Problem p00478 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <csignal>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
  string s, add, key;
  cin >> key;
  int n, cont = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    s += s;
    if (s.find(key) != string::npos) {
      cont++;
    }
  }
  cout << cont << endl;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string tmp;
  char word[11];
  scanf("%s", word);
  int n, m, cnt = 0, flag = 0, pos, index = 0;
  m = strlen(word);
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  for (int i = 0; i < n; i++) {
    while (true) {
      unsigned pos = s[i].find(word, index);
      if (pos != string::npos) {
        if (flag == 0) {
          cnt++;
          flag = 1;
        }
        index = pos + 1;
      } else {
        tmp = s[i];
        tmp += s[i];
        pos = 0;
        unsigned pos = tmp.find(word, index);
        if (pos != string::npos && pos >= 10 - m + 1 && pos < 10) {
          cnt++;
        }
        break;
      }
      flag = 0;
      index = 0;
      pos = 0;
    }
    cout << cnt << endl;
  }
}