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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge {
  int from, to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

string s;
vector<pair<char, int>> v;
int main() {
  cin >> s;
  if (s.size() < 3) {
    cout << 0 << endl;
    return 0;
  }
  int i = 0;
  char c = s[0];
  int cnt = 0;
  while (i < s.size()) {
    if (s[i] == c) {
      cnt++;
    } else {
      v.push_back(make_pair(c, cnt));
      cnt = 1;
      c = s[i];
    }
    i++;
  }
  v.push_back(make_pair(c, cnt));
  int ans = 0;
  if (v.size() > 2) {
    REP(i, v.size() - 2) {
      if (v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I') {
        if (v[i + 1].second <= v[i].second &&
            v[i + 1].second <= v[i + 2].second)
          ans = max(ans, v[i + 1].second);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) begin(a), end(a)
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge {
  int from, to, cost;
  bool operator<(const edge &e) const { return cost < e.cost; }
  bool operator>(const edge &e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

string s;
vector<pair<char, int>> v;
int main() {
  cin >> s;
  if (s.size() < 3) {
    cout << 0 << endl;
    return 0;
  }
  int i = 0;
  char c = s[0];
  int cnt = 0;
  while (i < s.size()) {
    if (s[i] == c) {
      cnt++;
    } else {
      v.push_back(make_pair(c, cnt));
      cnt = 1;
      c = s[i];
    }
    i++;
  }
  v.push_back(make_pair(c, cnt));
  int ans = 0;
  REP(i, v.size() - 2) {
    if (v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I') {
      if (v[i + 1].second <= v[i].second && v[i + 1].second <= v[i + 2].second)
        ans = max(ans, v[i + 1].second);
    }
  }
  cout << ans << endl;
  return 0;
}