#include<bits/stdc++.h>
using namespace std;
int N;
string S;
int f(char x) {
if(x == 'J') return 0;
if(x == 'O') return 1;
if(x == 'I') return 2;
}
struct node {
int a, b, c;
bool operator <(const node &i) const {
if(a != i.a) return a < i.a;
if(b != i.b) return b < i.b;
if(c != i.c) return c < i.c;
return false;
}
};
int cnt[3];
map<node, int> chk;
int main() {
cin >> N >> S;
int ans = 0;
chk[ {0, 0, 0} ] = -1;
for(int i = 0; i < N; i++) {
cnt[ f(S[i]) ]++;
int mn = min(cnt[0], min(cnt[1], cnt[2]));
if(chk.find({ cnt[0] - mn, cnt[1] - mn, cnt[2] - mn }) != chk.end()) {
ans = max(ans, i - chk[ { cnt[0] - mn, cnt[1] - mn, cnt[2] - mn } ]);
}
else chk[ { cnt[0] - mn, cnt[1] - mn, cnt[2] - mn } ] = i;
}
cout << ans;
}
Compilation message
joioji.cpp: In function 'int f(char)':
joioji.cpp:11:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
400 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
512 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
3 |
Correct |
13 ms |
1408 KB |
Output is correct |
4 |
Correct |
24 ms |
2304 KB |
Output is correct |
5 |
Correct |
39 ms |
3528 KB |
Output is correct |
6 |
Correct |
48 ms |
3656 KB |
Output is correct |
7 |
Correct |
52 ms |
4104 KB |
Output is correct |
8 |
Correct |
47 ms |
3592 KB |
Output is correct |
9 |
Correct |
46 ms |
3848 KB |
Output is correct |
10 |
Correct |
46 ms |
3592 KB |
Output is correct |
11 |
Correct |
41 ms |
5256 KB |
Output is correct |
12 |
Correct |
30 ms |
2316 KB |
Output is correct |
13 |
Correct |
32 ms |
1672 KB |
Output is correct |
14 |
Correct |
38 ms |
6280 KB |
Output is correct |
15 |
Correct |
27 ms |
1424 KB |
Output is correct |