alexjercan/bugnet huggingface dataset:
Problem p00890 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF (1e9)
#define N 105
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
int n, m, C, f, t, c;
vector<P> G[N];

int dijkstra() {
  int d[N][N];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      d[i][j] = INF;
  priority_queue<P1, vector<P1>, greater<P1>> q;
  d[0][0] = 0;
  q.push(P1(0, P(0, 0)));
  while (!q.empty()) {
    P1 a = q.top();
    q.pop();
    int cost = a.first;
    int cnt = a.second.first;
    int node = a.second.second;
    if (d[cnt][node] < cost)
      continue;
    for (int i = 0; i < G[node].size(); i++) {
      int nnode = G[node][i].first;
      int ncost = cost + G[node][i].second;
      if (d[cnt][nnode] > ncost) {
        d[cnt][nnode] = ncost;
        q.push(P1(ncost, P(cnt, nnode)));
      }
      if (cnt < n && d[cnt + 1][nnode] > cost) {
        d[cnt + 1][nnode] = cost;
        q.push(P1(cost, P(cnt + 1, nnode)));
      }
    }
  }
  for (int i = 0; i <= n; i++)
    if (C >= d[i][n - 1])
      return i;
}

int main() {
  while (1) {
    cin >> n >> m >> C;
    if (!n && !m && !C)
      break;
    for (int i = 0; i < m; i++) {
      cin >> f >> t >> c;
      f--, t--;
      G[f].push_back(P(t, c));
    }
    cout << dijkstra() << endl;
    for (int i = 0; i < n; i++)
      G[i].clear();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INF (1e9)
#define N 105
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
int n, m, C, f, t, c;
vector<P> G[N];

int dijkstra() {
  int d[N][N];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      d[i][j] = INF;
  priority_queue<P1, vector<P1>, greater<P1>> q;
  d[0][0] = 0;
  q.push(P1(0, P(0, 0)));
  while (!q.empty()) {
    P1 a = q.top();
    q.pop();
    int cost = a.first;
    int cnt = a.second.first;
    int node = a.second.second;
    if (d[cnt][node] < cost)
      continue;
    for (int i = 0; i < G[node].size(); i++) {
      int nnode = G[node][i].first;
      int ncost = cost + G[node][i].second;
      if (d[cnt][nnode] > ncost) {
        d[cnt][nnode] = ncost;
        q.push(P1(ncost, P(cnt, nnode)));
      }
      if (d[cnt + 1][nnode] > cost) {
        d[cnt + 1][nnode] = cost;
        q.push(P1(cost, P(cnt + 1, nnode)));
      }
    }
  }
  for (int i = 0; i <= n; i++)
    if (C >= d[i][n - 1])
      return i;
}

int main() {
  while (1) {
    cin >> n >> m >> C;
    if (!n && !m && !C)
      break;
    for (int i = 0; i < m; i++) {
      cin >> f >> t >> c;
      f--, t--;
      G[f].push_back(P(t, c));
    }
    cout << dijkstra() << endl;
    for (int i = 0; i < n; i++)
      G[i].clear();
  }
  return 0;
}
Problem p00890 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define clr clear()
#define pb push_back
#define sz size()
#define fs first
#define sc second
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P2;
const int INF = 1e8;

int n, m, c;
int f, t, cost;
vector<P> g[101];
int d[101][100001];

int main() {
  while (cin >> n >> m >> c, n) {
    rep(i, n) {
      g[i].clr;
      rep(j, c + 1) d[i][j] = INF;
    }

    rep(i, m) {
      cin >> f >> t >> cost;
      f--;
      t--;
      g[f].pb(P(cost, t));
    }

    priority_queue<P2, vector<P2>, greater<P2>> q;
    q.push(P2(0, P(0, 0)));
    d[0][0] = 0;

    while (q.sz) {
      P2 p = q.top();
      q.pop();
      int change = p.fs, v = p.sc.fs, dis = p.sc.sc;
      if (change > d[v][dis])
        continue;
      if (v == n - 1)
        break;

      rep(i, g[v].sz) {
        int nd = dis + g[v][i].fs, nv = g[v][i].sc;
        if (d[nv][dis] > change + 1) {
          d[nv][dis] = change + 1;
          q.push(P2(d[nv][dis], P(nv, dis)));
        }

        if (nd > c)
          continue;
        if (d[nv][nd] > change) {
          d[nv][nd] = change;
          q.push(P2(d[nv][nd], P(nv, nd)));
        }
      }
    }

    int ans = INF;
    rep(i, c + 1) ans = min(ans, d[n - 1][i]);
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define rep(i, a) for (int i = 0; i < (int)(a); i++)
#define clr clear()
#define pb push_back
#define sz size()
#define fs first
#define sc second
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P2;
const int INF = 1e8;

int n, m, c;
int f, t, cost;
vector<P> g[101];
int d[101][100001];

int main() {
  while (cin >> n >> m >> c, n) {
    rep(i, n) {
      g[i].clr;
      rep(j, c + 1) d[i][j] = INF;
    }

    rep(i, m) {
      cin >> f >> t >> cost;
      f--;
      t--;
      g[f].pb(P(cost, t));
    }

    priority_queue<P2, vector<P2>, greater<P2>> q;
    q.push(P2(0, P(0, 0)));
    d[0][0] = 0;

    while (q.sz) {
      P2 p = q.top();
      q.pop();
      int change = p.fs, v = p.sc.fs, dis = p.sc.sc;

      rep(i, g[v].sz) {
        int nd = dis + g[v][i].fs, nv = g[v][i].sc;
        if (d[nv][dis] > change + 1) {
          d[nv][dis] = change + 1;
          q.push(P2(d[nv][dis], P(nv, dis)));
        }

        if (nd > c)
          continue;
        if (d[nv][nd] > change) {
          d[nv][nd] = change;
          q.push(P2(d[nv][nd], P(nv, nd)));
        }
      }
    }

    int ans = INF;
    rep(i, c + 1) ans = min(ans, d[n - 1][i]);
    cout << ans << endl;
  }
}
Problem p00890 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

constexpr long long INF64 = 1e18;

using Weight = int;

struct Edge {
  int src, dst;
  Weight weight;
  int cost;
  Edge(int src, int dst, Weight weight, int cost = 0)
      : src(src), dst(dst), weight(weight), cost(cost) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, c;
  while (cin >> n >> m >> c, n) {
    vector<vector<int>> flag(n, vector<int>(m, 1e9));
    Graph g(n);
    for (int i = 0; i < m; ++i) {
      int f, t, cc;
      cin >> f >> t >> cc;
      g[f - 1].emplace_back(f - 1, t - 1, cc);
    }
    deque<Edge> q;
    for (q.emplace_back(-2, 0, 0, 0); !q.empty();) {
      Edge e = q.front();
      if (e.dst == n - 1) {
        cout << e.cost << endl;
        goto BREAK;
      }
      q.pop_front();
      for (auto ge : g[e.dst]) {
        if (flag[ge.dst][e.cost + 1] > e.weight) {
          q.emplace_back(ge.src, ge.dst, e.weight, e.cost + 1);
          flag[ge.dst][e.cost + 1] = e.weight;
        }
        if (ge.weight + e.weight > c)
          continue;
        if (flag[ge.dst][e.cost] > ge.weight + e.weight) {
          q.emplace_front(ge.src, ge.dst, ge.weight + e.weight, e.cost);
          flag[ge.dst][e.cost] = ge.weight + e.weight;
        }
      }
    }
    cout << "impossible" << endl;
  BREAK:;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

constexpr long long INF64 = 1e18;

using Weight = int;

struct Edge {
  int src, dst;
  Weight weight;
  int cost;
  Edge(int src, int dst, Weight weight, int cost = 0)
      : src(src), dst(dst), weight(weight), cost(cost) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, c;
  while (cin >> n >> m >> c, n) {
    vector<vector<int>> flag(n, vector<int>(m, 1e6));
    Graph g(n);
    for (int i = 0; i < m; ++i) {
      int f, t, cc;
      cin >> f >> t >> cc;
      g[f - 1].emplace_back(f - 1, t - 1, cc);
    }
    deque<Edge> q;
    for (q.emplace_back(-2, 0, 0, 0); !q.empty();) {
      Edge e = q.front();
      // cout << e.src << endl;
      if (e.dst == n - 1) {
        cout << e.cost << endl;
        goto BREAK;
      }
      q.pop_front();
      for (auto ge : g[e.dst]) {
        if (flag[ge.dst][e.cost + 1] > e.weight)
          q.emplace_back(ge.src, ge.dst, e.weight, e.cost + 1);
        if (ge.weight + e.weight > c)
          continue;
        if (flag[ge.dst][e.cost] > ge.weight + e.weight)
          q.emplace_front(ge.src, ge.dst, ge.weight + e.weight, e.cost);
      }
    }
    cout << "impossible" << endl;
  BREAK:;
  }
}
Problem p00890 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define MP make_pair
int main() {
  int n, m, c;
  while (cin >> n >> m >> c && n != 0) {
    vector<vector<int>> dp(n, vector<int>(m + 1, 2000000000));
    vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < m; i++) {
      int a, b, w;
      cin >> a >> b >> w;
      a--, b--;
      g[a].push_back(make_pair(b, w));
    }
    priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
                   greater<pair<int, pair<int, int>>>>
        pq;
    dp[0][0] = 0;
    pq.push(MP(0, MP(0, 0)));
    while (!pq.empty()) {
      auto x = pq.top();
      pq.pop();
      for (auto s : g[x.second.second]) {
        if (dp[s.first][x.second.first] > s.second + x.first) {
          dp[s.first][x.second.first] = s.second + x.first;
          pq.push(MP(s.second + x.first, MP(x.second.first, s.first)));
        }
        if (x.second.first + 1 > m)
          break;
        if (dp[s.first][x.second.first + 1] > x.first) {
          dp[s.first][x.second.first + 1] = x.first;
          pq.push(MP(x.first, MP(x.second.first + 1, s.first)));
        }
      }
    }
    for (int i = 0; i <= m; i++) {
      if (dp[n - 1][i] <= c) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define MP make_pair
int main() {
  int n, m, c;
  while (cin >> n >> m >> c && n != 0) {
    vector<vector<int>> dp(n, vector<int>(m + 1, 2000000000));
    vector<vector<pair<int, int>>> g(n);
    for (int i = 0; i < m; i++) {
      int a, b, w;
      cin >> a >> b >> w;
      a--, b--;
      g[a].push_back(make_pair(b, w));
    }
    priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
                   greater<pair<int, pair<int, int>>>>
        pq;
    dp[0][0] = 0;
    pq.push(MP(0, MP(0, 0)));
    while (!pq.empty()) {
      auto x = pq.top();
      pq.pop();
      for (auto s : g[x.second.first]) {
        if (dp[s.first][x.second.second] > s.second + x.first) {
          dp[s.first][x.second.second] = s.second + x.first;
          pq.push(MP(s.second + x.first, MP(s.first, x.second.second)));
        }
        if (dp[s.first][x.second.second + 1] > x.first) {
          dp[s.first][x.second.second + 1] = x.first;
          pq.push(MP(x.first, MP(s.first, x.second.second + 1)));
        }
      }
    }
    for (int i = 0; i <= m; i++) {
      if (dp[n - 1][i] <= c) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p00892 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;
const int INF = 10000000;

int M, N;
int X1[100 + 10], X2[100 + 10], Y[100 + 10], Z[100 + 10], P[200 + 10];
double ans;

double width(int *X, int *YZ, int n, double x) {
  double lb = INF, ub = -INF;
  for (int i = 0; i < n; i++) {
    double x1 = X[i], y1 = YZ[i], x2 = X[(i + 1) % n], y2 = YZ[(i + 1) % n];
    if ((x1 - x) * (x2 - x) <= 0 && x1 != x2) {
      double y = y1 + (y2 - y1) * (x - x1) / (x2 - x1);
      lb = min(lb, y);
      ub = max(ub, y);
    }
  }
  return max(0.0, ub - lb);
}

void solve() {
  ans = 0.0;
  int min1 = *min_element(X1, X1 + M);
  int min2 = *min_element(X2, X2 + N);
  int max1 = *max_element(X1, X1 + M);
  int max2 = *max_element(X2, X2 + N);

  sort(P, P + M + N);

  for (int i = 0; i < M + N - 1; i++) {
    double a = P[i];
    double b = P[i + 1];
    double c = (a + b) / 2;
    if (min1 <= c && min2 <= c && c <= max1 && c <= max2) {
      double fa = width(X1, Y, M, a) * width(X2, Z, N, a);
      double fb = width(X1, Y, M, b) * width(X2, Z, N, b);
      double fc = width(X1, Y, M, c) * width(X2, Z, N, c);
      ans += (b - a) / 6 * (fa + 4 * fc + fb);
    }
  }
  printf("%.10f\\n", ans);
}

int main() {
  while ((cin >> M >> N) && M && N) {
    for (int i = 0; i < M; i++) {
      cin >> X1[i] >> Y[i];
      P[i] = X1[i];
    }
    for (int i = 0; i < N; i++) {
      cin >> X2[i] >> Z[i];
      P[M + i] = X2[i];
    }
    solve();
  }

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;
const int INF = 200;

int M, N;
int X1[100 + 10], X2[100 + 10], Y[100 + 10], Z[100 + 10], P[200 + 10];
double ans;

double width(int *X, int *YZ, int n, double x) {
  double lb = INF, ub = -INF;
  for (int i = 0; i < n; i++) {
    double x1 = X[i], y1 = YZ[i], x2 = X[(i + 1) % n], y2 = YZ[(i + 1) % n];
    if ((x1 - x) * (x2 - x) <= 0 && x1 != x2) {
      double y = y1 + (y2 - y1) * (x - x1) / (x2 - x1);
      lb = min(lb, y);
      ub = max(ub, y);
    }
  }
  return max(0.0, ub - lb);
}

void solve() {
  ans = 0.0;
  int min1 = *min_element(X1, X1 + M);
  int min2 = *min_element(X2, X2 + N);
  int max1 = *max_element(X1, X1 + M);
  int max2 = *max_element(X1, X2 + N);

  sort(P, P + M + N);

  for (int i = 0; i < M + N - 1; i++) {
    double a = P[i];
    double b = P[i + 1];
    double c = (a + b) / 2;
    if (min1 <= c && min2 <= c && c <= max1 && c <= max2) {
      double fa = width(X1, Y, M, a) * width(X2, Z, N, a);
      double fb = width(X1, Y, M, b) * width(X2, Z, N, b);
      double fc = width(X1, Y, M, c) * width(X2, Z, N, c);
      ans += (b - a) / 6 * (fa + 4 * fc + fb);
    }
  }
  printf("%.10f\\n", ans);
}

int main() {
  while ((cin >> M >> N) && M && N) {
    for (int i = 0; i < M; i++) {
      cin >> X1[i] >> Y[i];
      P[i] = X1[i];
    }
    for (int i = 0; i < N; i++) {
      cin >> X2[i] >> Z[i];
      P[M + i] = X2[i];
    }
    solve();
  }

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

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define mk make_pair
#define fi first
#define se second
using namespace std;
struct B {
  int size;
  vector<int> dat;
  void init(int n) {
    size = n;
    dat.clear();
    dat.resize(n + 1);
  }
  void Add(int i, int x) {
    while (0 < i && i <= size)
      dat[i] += x, i += (i & -i);
  }
  int Sum(int i) {
    int res = 0;
    while (0 < i)
      res += dat[i], i -= (i & -i);
    return res;
  }
};
int main() {
  int n;
  while (cin >> n, n) {
    int ans = 0;
    vector<int> v[1001];
    for (int i = 0; i < n; i++) {
      int pp = 0, m, d, h, ss, t;
      scanf("%d/%d %d:%d", &m, &d, &h, &ss);
      pp = m * 40 * 24 * 60 + d * 24 * 60 + h * 60 + ss;
      string s1, s2;
      cin >> s1 >> t;
      v[t].push_back(pp);
    }
    for (int o = 1; o < 1001; o++)
      if (v[o].size()) {
        B A, B;
        A.init(900000);
        B.init(900000);
        for (int i = 0; i < v[o].size(); i += 2) {
          int ss = v[o][i], tt = v[o][i + 1];
          ss += 11, tt += 10;
          A.Add(ss, 1);
          A.Add(tt, -1);
          B.Add(ss, (-1) * (ss - 1));
          B.Add(tt, (ss - 1) + (tt - ss + 1));
        }
        int sum = 0;
        for (int i = 0; i < v[0].size(); i += 2) {
          int ss = v[0][i], tt = v[0][i + 1];
          ss += 10;
          tt += 10;
          sum += A.Sum(tt) * tt + B.Sum(tt) - A.Sum(ss) * ss - B.Sum(ss);
        }
        ans = max(sum, ans);
      }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define mk make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
struct B {
  int size;
  vector<ll> dat;
  void init(int n) {
    size = n;
    dat.clear();
    dat.resize(n + 1);
  }
  void Add(int i, ll x) {
    while (0 < i && i <= size)
      dat[i] += x, i += (i & -i);
  }
  ll Sum(int i) {
    ll res = 0;
    while (0 < i)
      res += dat[i], i -= (i & -i);
    return res;
  }
};
int main() {
  int n;
  while (cin >> n, n) {
    int ans = 0;
    vector<int> v[1001];
    for (int i = 0; i < n; i++) {
      int pp = 0, m, d, h, ss, t;
      scanf("%d/%d %d:%d", &m, &d, &h, &ss);
      pp = m * 40 * 24 * 60 + d * 24 * 60 + h * 60 + ss;
      string s1, s2;
      cin >> s1 >> t;
      v[t].push_back(pp);
    }
    for (int o = 1; o < 1001; o++)
      if (v[o].size()) {
        B A, B;
        A.init(700000);
        B.init(700000);
        for (int i = 0; i < v[o].size(); i += 2) {
          int ss = v[o][i], tt = v[o][i + 1];
          A.Add(ss, 1);
          A.Add(tt, -1);
          B.Add(ss, -1 * (ss - 1));
          B.Add(tt, 1 * (ss - 1) + 1 * (tt - ss + 1));
        }
        int sum = 0;
        for (int i = 0; i < v[0].size(); i += 2) {
          int ss = v[0][i], tt = v[0][i + 1];
          ss;
          sum += A.Sum(tt) * tt + B.Sum(tt) - A.Sum(ss) * ss - B.Sum(ss);
        }
        ans = max(sum, ans);
      }
    cout << ans << endl;
  }
}
Problem p00894 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#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()

int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int func(int m, int d, int h, int min) {
  int res = 0;
  REP(i, m - 1) { res += month[i]; }
  res += d;
  res *= 60 * 24;
  res += h * 60;
  res += min;
  return res;
}

int main() {
  int n;
  while (cin >> n, n) {
    bool table[31 * 12 * 24 * 60];
    int m[n], d[n], h[n], min[n], p[n];
    char c[n];

    int start[1000];
    int point[1000];
    memset(table, 0, sizeof(table));
    memset(point, 0, sizeof(point));

    int godstart;
    REP(i, n) {
      scanf("%d/%d %d:%d %c %d", m + i, d + i, h + i, min + i, c + i, p + i);
      // cout << m[i] << " " << d[i] << " " << p[i] << endl;
      if (p[i] == 0) {
        if (c[i] == 'I') {
          godstart = func(m[i], d[i], h[i], min[i]);
        } else {
          for (int j = godstart; j < func(m[i], d[i], h[i], min[i]); ++j) {
            table[j] = 1;
          }
        }
      }
    }
    REP(i, n) {
      if (p[i] == 0)
        continue;
      if (c[i] == 'I') {
        start[p[i]] = func(m[i], d[i], h[i], min[i]);
      } else {
        for (int j = start[p[i]]; j < func(m[i], d[i], h[i], min[i]); ++j) {
          if (table[j]) {
            // printf("%d:%d\\n", i, j);
            point[p[i]]++;
          }
        }
      }
    }
    cout << *max_element(point, point + 1000) << endl;
    ;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#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()
const int INF = 1 << 29;

bool god[12][31][24 * 60];
int man[1000];

int main() {
  int n;
  while (cin >> n, n) {
    int month[n], day[n], h[n], m[n], p[n];
    char e[n];
    int godstart;
    memset(god, 0, sizeof(god));
    REP(i, n) {
      scanf("%d/%d %d:%d %c %d\\n", month + i, day + i, h + i, m + i, e + i,
            p + i);
      if (p[i] == 0) {
        if (e[i] == 'I')
          godstart = h[i] * 60 + m[i];
        else {
          for (int j = godstart; j < h[i] * 60 + m[i]; ++j)
            god[month[i]][day[i]][j] = 1;
        }
      }
    }
    vector<int> table(1000);

    REP(i, n) {
      if (p[i] == 0)
        continue;
      if (e[i] == 'I')
        man[p[i]] = h[i] * 60 + m[i];
      else {
        for (int j = man[p[i]]; j < h[i] * 60 + m[i]; ++j)
          if (god[month[i]][day[i]][j])
            table[p[i]]++;
      }
    }
    cout << *max_element(ALL(table)) << endl;
  }
}
Problem p00894 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstring>
#include <iostream>

using namespace std;

int main() {
  int in[1000];   // inµÄ¢é©Ç¤©
  int stay[1000]; // ØÝJnÔ
  int sum[1000];  // vØÝÔ
  int out;
  int n;
  int nowday, nowmon;

  while (cin >> n, n) {
    memset(in, 0, sizeof(in));
    memset(stay, 0, sizeof(stay));
    memset(sum, 0, sizeof(sum));
    out = 0;

    for (int i = 0; i < n; i++) {
      int mt, dy, hr, mn, id, stime;
      char c, io;

      cin >> mt >> c >> dy;
      cin >> hr >> c >> mn;
      cin >> io;
      cin >> id;

      stime = hr * 60 + mn;

      if (io == 'I') {
        in[id] = 1;
        stay[id] = mn + 60 * hr;
      } else {
        if (id == 0) {
          for (int j = 0; j < 1000; j++) {
            if (in[j] == 1) {
              sum[j] += min(stime - stay[j], stime - stay[0]);
            }
          }
        } else {
          if (in[0] == 1) {
            sum[id] += min(stime - stay[id], stime - stay[0]);
          }
        }

        in[id] = 0;
      }
    }

    for (int i = 1; i < 1000; i++) {
      if (sum[i] > out)
        out = sum[i];
    }

    cout << out << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>

using namespace std;

int main() {
  int in[1000];   // inµÄ¢é©Ç¤©
  int stay[1000]; // ØÝJnÔ
  int sum[1000];  // vØÝÔ
  int out;
  int n;
  int nowday, nowmon;

  while (cin >> n, n) {
    memset(in, 0, sizeof(in));
    memset(stay, 0, sizeof(stay));
    memset(sum, 0, sizeof(sum));
    out = 0;

    nowday = 0;
    nowmon = 0;

    for (int i = 0; i < n; i++) {
      int mt, dy, hr, mn, id, stime;
      char c, io;

      cin >> mt >> c >> dy;
      cin >> hr >> c >> mn;
      cin >> io;
      cin >> id;

      if (dy != nowday || nowmon != mn) {
        nowday = dy;
        nowmon = mn;
        for (i = 0; i < 1000; i++) {
          in[i] = 0;
        }
      }

      stime = hr * 60 + mn;

      if (io == 'I') {
        in[id] = 1;
        stay[id] = mn + 60 * hr;
      } else {
        if (id == 0) {
          for (int i = 0; i < 1000; i++) {
            if (in[i] == 1) {
              sum[i] += min(stime - stay[i], stime - stay[0]);
            }
          }
        } else {
          if (in[0] == 1) {
            sum[id] += min(stime - stay[id], stime - stay[0]);
          }
        }

        in[id] = 0;
      }
    }

    for (int i = 1; i < 1000; i++) {
      if (sum[i] > out)
        out = sum[i];
    }

    cout << out << endl;
  }

  return 0;
}