This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
for (const pair<int,vector<int>> &p : runs) {
const vector<int> &v = p.second;
map<int,int> fi;
for (int i : v) {
if (fi.count(OI[i])) {
ans = max(ans, i - fi[OI[i]]);
} else {
fi[OI[i]] = i;
}
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |