#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#define PI pair<int, int>
using namespace std;
int n, l, r, md, ans, mx, s[3][200005];
set<PI> v;
map<PI, int> b1;
string a;
int main()
{
int i, z, t1, t2;
cin >> n;
cin >> a;
a = ' ' + a;
for (i = 1; i <= n;i++) {
s[0][i] = s[0][i - 1];
s[1][i] = s[1][i - 1];
s[2][i] = s[2][i - 1];
if (a[i] == 'J') s[0][i]++;
else if (a[i] == 'O') s[1][i]++;
else s[2][i]++;
}
v.insert(PI(n, n));
b1[PI(n, n)] = 0;
for (i = 1; i <= n; i++) {
t1 = s[0][i] - s[1][i] + n;
t2 = s[1][i] - s[2][i] + n;
if (v.count(PI(t1, t2)) == 0) {
v.insert(PI(t1, t2));
b1[PI(t1, t2)] = i;
} else {
mx = max(mx, i - b1[PI(t1, t2)]);
}
}
cout << mx;
return 0;
}
Compilation message
joioji.cpp: In function 'int main()':
joioji.cpp:14:9: warning: unused variable 'z' [-Wunused-variable]
int i, z, t1, t2;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
356 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
3 ms |
432 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
668 KB |
Output is correct |
9 |
Correct |
2 ms |
668 KB |
Output is correct |
10 |
Correct |
2 ms |
668 KB |
Output is correct |
11 |
Correct |
3 ms |
668 KB |
Output is correct |
12 |
Correct |
2 ms |
668 KB |
Output is correct |
13 |
Correct |
2 ms |
668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
668 KB |
Output is correct |
2 |
Correct |
3 ms |
668 KB |
Output is correct |
3 |
Correct |
4 ms |
672 KB |
Output is correct |
4 |
Correct |
5 ms |
676 KB |
Output is correct |
5 |
Correct |
4 ms |
800 KB |
Output is correct |
6 |
Correct |
4 ms |
800 KB |
Output is correct |
7 |
Correct |
3 ms |
800 KB |
Output is correct |
8 |
Correct |
4 ms |
800 KB |
Output is correct |
9 |
Correct |
4 ms |
876 KB |
Output is correct |
10 |
Correct |
3 ms |
976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
976 KB |
Output is correct |
2 |
Correct |
17 ms |
1944 KB |
Output is correct |
3 |
Correct |
20 ms |
3064 KB |
Output is correct |
4 |
Correct |
41 ms |
5096 KB |
Output is correct |
5 |
Correct |
67 ms |
7528 KB |
Output is correct |
6 |
Correct |
81 ms |
8244 KB |
Output is correct |
7 |
Correct |
92 ms |
9236 KB |
Output is correct |
8 |
Correct |
107 ms |
9236 KB |
Output is correct |
9 |
Correct |
84 ms |
9236 KB |
Output is correct |
10 |
Correct |
97 ms |
9236 KB |
Output is correct |
11 |
Correct |
77 ms |
10832 KB |
Output is correct |
12 |
Correct |
61 ms |
10832 KB |
Output is correct |
13 |
Correct |
56 ms |
10832 KB |
Output is correct |
14 |
Correct |
69 ms |
12384 KB |
Output is correct |
15 |
Correct |
32 ms |
12384 KB |
Output is correct |