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;
#define int long long
int N, A, JP[200005], OP[200005], IP[200005];
char S[200005];
map<pair<int, int>, int> M;
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> S[i];
JP[i] = JP[i - 1];
OP[i] = OP[i - 1];
IP[i] = IP[i - 1];
if (S[i] == 'J') JP[i]++;
else if (S[i] == 'O') OP[i]++;
else IP[i]++;
}
M[make_pair(0, 0)] = 0;
for (int i = 1; i <= N; i++) {
if (M.find(make_pair(JP[i] - OP[i], OP[i] - IP[i])) != M.end()) A = max(A, i - M[make_pair(JP[i] - OP[i], OP[i] - IP[i])]);
else M[make_pair(JP[i] - OP[i], OP[i] - IP[i])] = i;
}
cout << A << '\n';
}
Compilation message (stderr)
joioji.cpp:9:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |