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 <iostream>
#include <cstdio>
#include <map>
#define PII pair<int, int>
using namespace std;
int n, mx, cj, co, ci;
string a;
PII t;
map<PII, int> m;
int main()
{
int i;
cin >> n >> a;
a = '_' + a;
cj = co = ci = 0;
m[{0, 0}] = 0;
for (i = 1; i <= n; i++) {
if (a[i] == 'J') cj++;
else if (a[i] == 'O') co++;
else ci++;
t = {cj - co, cj - ci};
if (!m.count(t)) m[t] = i;
else mx = max(mx, i - m[t]);
}
cout << mx << endl;
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... |