#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
const int mod = 1e9 + 7;
const int inf = 1e9;
int add(int x, int y) {
return (1ll * x + 1ll * y) % mod;
}
int del(int x, int y) {
return ((1ll * x - 1ll * y) % mod + mod) % mod;
}
int mul(int x, int y) {
return (1ll * x * 1ll * y) % mod;
}
map<pair<int, ii>, int> mymap;
int sum1, sum2, sum3, n;
string s;
int main() {
cin.tie(0), ios_base::sync_with_stdio(0);
cin >> n;
cin >> s;
s = "+" + s;
mymap[{0, {0, 0}}] = 0;
int ans = 0;
for(int i = 1; i <= n; i++) {
if(s[i] == 'J')
sum1++;
else if(s[i] == 'O')
sum2++;
else
sum3++;
int lmao1 = sum1, lmao2 = sum2, lmao3 = sum3;
lmao1 -= min(min(sum1, sum2), sum3);
lmao2 -= min(min(sum1, sum2), sum3);
lmao3 -= min(min(sum1, sum2), sum3);
//cout << lmao1 << " " << lmao2 << " " << lmao3 << " " << mymap.count({lmao1, {lmao2, lmao3}}) << "\n";
if(mymap.count({lmao1, {lmao2, lmao3}}))
ans = max(ans, i - mymap[{lmao1, {lmao2, lmao3}}]);
if(mymap.count({lmao1, {lmao2, lmao3}}) == 0)
mymap[{lmao1, {lmao2, lmao3}}] = i;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
11 ms |
1016 KB |
Output is correct |
3 |
Correct |
17 ms |
1400 KB |
Output is correct |
4 |
Correct |
32 ms |
2164 KB |
Output is correct |
5 |
Correct |
50 ms |
3312 KB |
Output is correct |
6 |
Correct |
65 ms |
3392 KB |
Output is correct |
7 |
Correct |
65 ms |
3984 KB |
Output is correct |
8 |
Correct |
63 ms |
3388 KB |
Output is correct |
9 |
Correct |
63 ms |
3644 KB |
Output is correct |
10 |
Correct |
62 ms |
3444 KB |
Output is correct |
11 |
Correct |
59 ms |
5048 KB |
Output is correct |
12 |
Correct |
40 ms |
2164 KB |
Output is correct |
13 |
Correct |
41 ms |
1480 KB |
Output is correct |
14 |
Correct |
52 ms |
6120 KB |
Output is correct |
15 |
Correct |
31 ms |
1216 KB |
Output is correct |