#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int cnti[N], cntj[N], cnto[N];
map <pair <int, int>, int> m;
string s;
int n;
int main()
{
cin >> n;
cin >> s;
s = "1" + s;
for(int i = 1; i <= n; i++)
{
cnti[i] = cnti[i - 1] + (s[i] == 'I');
cntj[i] = cntj[i - 1] + (s[i] == 'J');
cnto[i] = cnto[i - 1] + (s[i] == 'O');
pair <int, int> v = {cntj[i] - cnti[i], cntj[i] - cnto[i]};
if(m[v] == 0)
m[v] = i;
}
int ans = 0;
for(int i = n; i >= 1; i--)
{
pair <int, int> v = {cntj[i] - cnti[i], cntj[i] - cnto[i]};
int j = m[v];
ans = max(ans, i - j);
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
508 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
632 KB |
Output is correct |
2 |
Correct |
11 ms |
1272 KB |
Output is correct |
3 |
Correct |
17 ms |
2040 KB |
Output is correct |
4 |
Correct |
32 ms |
3404 KB |
Output is correct |
5 |
Correct |
49 ms |
5164 KB |
Output is correct |
6 |
Correct |
61 ms |
5840 KB |
Output is correct |
7 |
Correct |
64 ms |
6456 KB |
Output is correct |
8 |
Correct |
61 ms |
5784 KB |
Output is correct |
9 |
Correct |
62 ms |
5956 KB |
Output is correct |
10 |
Correct |
59 ms |
5724 KB |
Output is correct |
11 |
Correct |
56 ms |
7260 KB |
Output is correct |
12 |
Correct |
40 ms |
4300 KB |
Output is correct |
13 |
Correct |
37 ms |
3660 KB |
Output is correct |
14 |
Correct |
60 ms |
7916 KB |
Output is correct |
15 |
Correct |
37 ms |
3524 KB |
Output is correct |