#include <stdio.h>
#include <map>
using namespace std;
int N,ans;
char a[200010];
struct data{
int j,o,i;
bool operator < (const data x) const{
if(j != x.j) return j < x.j;
if(o != x.o) return o < x.o;
return i < x.i;
}
data(int ij,int io,int ii){
j = ij;
o = io;
i = ii;
}
};
map<data,int> Map;
int main(){
int i,tmp;
int cj,co,ci;
cj = co = ci = 0;
//freopen("input.txt","r",stdin);
scanf("%d\n",&N);
gets(a);
Map[data(0,0,0)] = 0;
for(i=1; i<=N; i++){
if(a[i-1] == 'J'){
cj++;
}else if(a[i-1] == 'O'){
co++;
}else{
ci++;
}
if(Map.find(data(cj-co,co-ci,ci-cj)) != Map.end()){
tmp = Map[data(cj-co,co-ci,ci-cj)];
if(ans < i-tmp) ans = i-tmp;
}else{
Map[data(cj-co,co-ci,ci-cj)] = i;
}
}
printf("%d\n",ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1408 KB |
Output is correct |
2 |
Correct |
0 ms |
1408 KB |
Output is correct |
3 |
Correct |
0 ms |
1408 KB |
Output is correct |
4 |
Correct |
0 ms |
1408 KB |
Output is correct |
5 |
Correct |
0 ms |
1408 KB |
Output is correct |
6 |
Correct |
0 ms |
1408 KB |
Output is correct |
7 |
Correct |
0 ms |
1408 KB |
Output is correct |
8 |
Correct |
0 ms |
1408 KB |
Output is correct |
9 |
Correct |
0 ms |
1408 KB |
Output is correct |
10 |
Correct |
0 ms |
1408 KB |
Output is correct |
11 |
Correct |
0 ms |
1408 KB |
Output is correct |
12 |
Correct |
0 ms |
1408 KB |
Output is correct |
13 |
Correct |
0 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1408 KB |
Output is correct |
2 |
Correct |
0 ms |
1408 KB |
Output is correct |
3 |
Correct |
0 ms |
1408 KB |
Output is correct |
4 |
Correct |
0 ms |
1408 KB |
Output is correct |
5 |
Correct |
0 ms |
1408 KB |
Output is correct |
6 |
Correct |
0 ms |
1408 KB |
Output is correct |
7 |
Correct |
0 ms |
1408 KB |
Output is correct |
8 |
Correct |
0 ms |
1408 KB |
Output is correct |
9 |
Correct |
0 ms |
1408 KB |
Output is correct |
10 |
Correct |
0 ms |
1540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1540 KB |
Output is correct |
2 |
Correct |
7 ms |
1936 KB |
Output is correct |
3 |
Correct |
12 ms |
2332 KB |
Output is correct |
4 |
Correct |
21 ms |
3124 KB |
Output is correct |
5 |
Correct |
30 ms |
4180 KB |
Output is correct |
6 |
Correct |
45 ms |
4312 KB |
Output is correct |
7 |
Correct |
46 ms |
4708 KB |
Output is correct |
8 |
Correct |
46 ms |
4180 KB |
Output is correct |
9 |
Correct |
45 ms |
4444 KB |
Output is correct |
10 |
Correct |
44 ms |
4180 KB |
Output is correct |
11 |
Correct |
35 ms |
5896 KB |
Output is correct |
12 |
Correct |
39 ms |
2992 KB |
Output is correct |
13 |
Correct |
26 ms |
2332 KB |
Output is correct |
14 |
Correct |
34 ms |
6952 KB |
Output is correct |
15 |
Correct |
19 ms |
1936 KB |
Output is correct |