#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
const ll N = 100+5 , INF = 1e18 , MOD = 1e9+7;
void solve(){
ll n;
string s;
cin >> n >> s;
s = ' '+s;
ll cj = 0 , ci = 0 , co = 0;
map<pair<ll,ll>,ll> m;
m[make_pair(0,0)] = 0;
ll ans = 0;
for(ll i = 1; i <= n; i++){
if(s[i] == 'J') cj++;
else if(s[i] == 'O') co++;
else ci++;
if(m.find(make_pair(cj-co,cj-ci)) == m.end()) m[make_pair(cj-co,cj-ci)] = i;
else ans = max(ans,i-m[make_pair(cj-co,cj-ci)]);
}
cout << ans;
}
int main(){
fast;
ll tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
456 KB |
Output is correct |
2 |
Correct |
5 ms |
876 KB |
Output is correct |
3 |
Correct |
9 ms |
1364 KB |
Output is correct |
4 |
Correct |
18 ms |
2248 KB |
Output is correct |
5 |
Correct |
28 ms |
3424 KB |
Output is correct |
6 |
Correct |
35 ms |
3524 KB |
Output is correct |
7 |
Correct |
35 ms |
4104 KB |
Output is correct |
8 |
Correct |
35 ms |
3508 KB |
Output is correct |
9 |
Correct |
36 ms |
3688 KB |
Output is correct |
10 |
Correct |
39 ms |
3476 KB |
Output is correct |
11 |
Correct |
30 ms |
5128 KB |
Output is correct |
12 |
Correct |
27 ms |
2204 KB |
Output is correct |
13 |
Correct |
22 ms |
1512 KB |
Output is correct |
14 |
Correct |
25 ms |
6200 KB |
Output is correct |
15 |
Correct |
16 ms |
1276 KB |
Output is correct |