Submission #849510

# Submission time Handle Problem Language Result Execution time Memory
849510 2023-09-14T21:04:35 Z myst6 JOIOJI (JOI14_joioji) C++14
0 / 100
1 ms 600 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  // one table of J-O
  // one table of O-I
  int ans = 0;
  vector<int> JO(N+1), OI(N+1);
  int j = 0, o = 0, i = 0, idx = 0;
  for (char c : s) {
    if (c == 'J') j++;
    if (c == 'O') o++;
    if (c == 'I') i++;
    idx++;
    JO[idx] = j-o;
    OI[idx] = o-i;
  }
  map<int,vector<int>> runs;
  for (int i=0; i<=N; i++) {
    runs[JO[i]].push_back(i);
  }
  map<int,int> fi;
  for (const pair<int,vector<int>> &p : runs) {
    const vector<int> &v = p.second;
    for (int i : v) {
      if (fi.count(OI[i])) {
        ans = max(ans, i - fi[OI[i]] - 1);
      } else {
        fi[OI[i]] = i;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -