#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, I[200005], J[200005], O[200005], res = 0;
bool check(int x){
for(int i = 1;i <= n - x + 1;i++){
int a = O[i + x - 1] - O[i - 1];
int b = J[i + x - 1] - J[i - 1];
int c = I[i + x - 1] - I[i - 1];
if(a == b && b == c) return true;
}
return false;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1;i <= n;i++){
char x; cin >> x;
O[i] = O[i - 1];
J[i] = J[i - 1];
I[i] = I[i - 1];
if(x == 'I') I[i]++;
if(x == 'J') J[i]++;
if(x == 'O') O[i]++;
}
int l = 0, r = n / 3;
while(r >= l){
int mid = (r + l) / 2;
if(check(mid * 3)){
res = mid * 3;
l = mid + 1;
}
else r = mid - 1;
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |