#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 |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
608 KB |
Output is correct |
3 |
Correct |
2 ms |
680 KB |
Output is correct |
4 |
Correct |
2 ms |
680 KB |
Output is correct |
5 |
Correct |
2 ms |
680 KB |
Output is correct |
6 |
Correct |
2 ms |
680 KB |
Output is correct |
7 |
Correct |
2 ms |
712 KB |
Output is correct |
8 |
Correct |
2 ms |
716 KB |
Output is correct |
9 |
Correct |
2 ms |
720 KB |
Output is correct |
10 |
Correct |
2 ms |
728 KB |
Output is correct |
11 |
Correct |
2 ms |
784 KB |
Output is correct |
12 |
Correct |
2 ms |
784 KB |
Output is correct |
13 |
Correct |
2 ms |
784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1048 KB |
Output is correct |
2 |
Correct |
3 ms |
1048 KB |
Output is correct |
3 |
Correct |
3 ms |
1048 KB |
Output is correct |
4 |
Correct |
3 ms |
1048 KB |
Output is correct |
5 |
Correct |
3 ms |
1112 KB |
Output is correct |
6 |
Correct |
3 ms |
1112 KB |
Output is correct |
7 |
Correct |
3 ms |
1112 KB |
Output is correct |
8 |
Correct |
3 ms |
1112 KB |
Output is correct |
9 |
Correct |
3 ms |
1112 KB |
Output is correct |
10 |
Correct |
3 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1152 KB |
Output is correct |
2 |
Correct |
9 ms |
1676 KB |
Output is correct |
3 |
Correct |
14 ms |
2108 KB |
Output is correct |
4 |
Correct |
37 ms |
3136 KB |
Output is correct |
5 |
Correct |
44 ms |
4464 KB |
Output is correct |
6 |
Correct |
50 ms |
4736 KB |
Output is correct |
7 |
Correct |
65 ms |
5444 KB |
Output is correct |
8 |
Correct |
50 ms |
5444 KB |
Output is correct |
9 |
Correct |
51 ms |
5600 KB |
Output is correct |
10 |
Correct |
51 ms |
5600 KB |
Output is correct |
11 |
Correct |
46 ms |
7304 KB |
Output is correct |
12 |
Correct |
40 ms |
7304 KB |
Output is correct |
13 |
Correct |
32 ms |
7304 KB |
Output is correct |
14 |
Correct |
39 ms |
8896 KB |
Output is correct |
15 |
Correct |
24 ms |
8896 KB |
Output is correct |