Problem p00894 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1e9;
const int64_t inf64 = 1e18;
const double eps = 1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

struct S {
  string date;
  int begin, end;

  S() {}

  S(string s, int b, int e) {
    date = s;
    begin = b;
    end = e;
  }
};

void solve(int n) {
  vector<S> data[500];
  vector<int> ans(500, 0);

  rep(i, 0, n) {
    string d;
    cin >> d;

    string temp;
    cin >> temp;

    int time = (temp[0] - '0') * 600 + (temp[1] - '0') * 60 +
               (temp[3] - '0') * 10 + (temp[4] - '0');

    string io;
    cin >> io;

    string sid;
    cin >> sid;

    int id = (sid[0] - '0') * 100 + (sid[1] - '0') * 10 + (sid[2] - '0');

    if (io == "I") {
      data[id].push_back(S(d, time, 0));
    } else {
      data[id][data[id].size() - 1].end = time;
    }
  }

  rep(i, 1, 500) {
    rep(j, 0, data[0].size()) {
      rep(k, 0, data[i].size()) {
        if (data[0][j].date != data[i][k].date) {
          continue;
        }

        int t_begin = max(data[0][j].begin, data[i][k].begin);
        int t_end = min(data[0][j].end, data[i][k].end);
        int t_ans = max(0, t_end - t_begin);

        ans[i] += t_ans;
      }
    }
  }

  int answer = 0;

  rep(i, 0, 500) { answer = max(answer, ans[i]); }

  cout << answer << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(10);

  while (true) {
    int n;
    cin >> n;

    if (n == 0)
      break;

    solve(n);
  }
  return 0;
}

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

#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1e9;
const int64_t inf64 = 1e18;
const double eps = 1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

struct S {
  string date;
  int begin, end;

  S() {}

  S(string s, int b, int e) {
    date = s;
    begin = b;
    end = e;
  }
};

void solve(int n) {
  vector<S> data[600];
  vector<int> ans(600, 0);

  rep(i, 0, n) {
    string d;
    cin >> d;

    string temp;
    cin >> temp;

    int time = (temp[0] - '0') * 600 + (temp[1] - '0') * 60 +
               (temp[3] - '0') * 10 + (temp[4] - '0');

    string io;
    cin >> io;

    string sid;
    cin >> sid;

    int id = (sid[0] - '0') * 100 + (sid[1] - '0') * 10 + (sid[2] - '0');

    if (io == "I") {
      data[id].push_back(S(d, time, 0));
    } else {
      data[id][data[id].size() - 1].end = time;
    }
  }

  rep(i, 1, 500) {
    rep(j, 0, data[0].size()) {
      rep(k, 0, data[i].size()) {
        if (data[0][j].date != data[i][k].date) {
          continue;
        }

        int t_begin = max(data[0][j].begin, data[i][k].begin);
        int t_end = min(data[0][j].end, data[i][k].end);
        int t_ans = max(0, t_end - t_begin);

        ans[i] += t_ans;
      }
    }
  }

  int answer = 0;

  rep(i, 0, 500) { answer = max(answer, ans[i]); }

  cout << answer << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(10);

  while (true) {
    int n;
    cin >> n;

    if (n == 0)
      break;

    solve(n);
  }
  return 0;
}