Problem p00894 (C++) — buggy submission, verdict: Runtime Error

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \\
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \\
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == v.size() ? "" : " ");
  return os;
}

int n;
int sum[1000], in[1000];

int main() {
  while (~scanf("%d\\n", &n) && n) {
    memset(sum, 0, sizeof(sum));
    memset(in, -1, sizeof(in));
    rep(i, n) {
      int M, D, h, m;
      char s[2];
      int id;
      scanf("%02d/%02d %02d:%02d %s %03d ", &M, &D, &h, &m, s, &id);
      // dump(M,D,h,m,s,id);
      if (s[0] == 'I')
        in[id] = h * 60 + m;
      else {
        int t = h * 60 + m;
        if (id == 0) {
          rep(j, 1000) if (j) {
            if (in[j] != -1)
              sum[j] += t - max(in[j], in[0]);
          }
        } else {
          if (in[0] != -1)
            sum[id] += t - max(in[id], in[0]);
        }
        in[id] = -1;
      }
    }
    printf("%d\\n", *max_element(sum + 1, sum + 1000));
  }
}

Error: 0

Fixed submission:

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i, a, b) for (ll i = a; i < ll(b); i++)
#define rep(i, b) loop(i, 0, b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...)                                                              \\
  (cerr << #__VA_ARGS__ << " = " << (DUMP(), __VA_ARGS__).str() << " ["        \\
        << __LINE__ << "]" << endl)
struct DUMP : ostringstream {
  template <class T> DUMP &operator,(const T &t) {
    if (this->tellp())
      *this << ", ";
    *this << t;
    return *this;
  }
};
#else
#define dump(...)
#endif
template <class T> ostream &operator<<(ostream &os, vector<T> const &v) {
  rep(i, v.size()) os << v[i] << (i + 1 == v.size() ? "" : " ");
  return os;
}

int N;
int sum[1000];
vector<pair<int, int>> logs[1000];

int exist[300000];

int f(int m, int d, int h, int M) {
  return m * 60 * 24 * 30 + d * 60 * 24 + h * 60 + M;
}

int main() {
  // #ifdef DEBUG
  //     freopen("in","r",stdin);
  // #endif
  while (~scanf("%d\\n", &N) && N) {
    rep(i, 1000) logs[i].clear();
    memset(exist, 0, sizeof(exist));
    memset(sum, 0, sizeof(sum));
    rep(i, N) {
      int t, id;
      char io;
      int m, d, h, M;
      scanf("%d/%d %d:%d ", &m, &d, &h, &M);
      t = f(m, d, h, M);
      cin >> io >> id;
      if (io == 'I') {
        logs[id].eb(t, f(m, d, 24, 0));
        if (id == 0)
          exist[t]++;
      } else {
        logs[id].back().second = t;
        if (id == 0)
          exist[t]--;
      }
    }
    rep(i, 300000 - 1) exist[i + 1] += exist[i];
    rep(i, 300000 - 1) exist[i + 1] += exist[i];
    int ans = 0;
    rep(i, 1000) if (i) {
      for (auto &p : logs[i]) {
        int l, r;
        tie(l, r) = p;
        sum[i] += exist[r] - exist[l];
      }
      ans = max(ans, sum[i]);
    }
    cout << ans << endl;
  }
}