#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;
string s;
ll n;
bool check(ll length){
ll j=0,i=0,o=0;
for(ll k = 1; k <= length; k++){
if(s[k] == 'J') j++;
else if(s[k] == 'O') o++;
else i++;
}
if(j == i && i == o) return true;
for(ll k = length+1; k <= n; k++){
if(s[k-length] == 'J') j--;
else if(s[k-length] == 'O') o--;
else i--;
if(s[k] == 'J') j++;
else if(s[k] == 'O') o++;
else i++;
if(j == i && i == o) return true;
}
return false;
}
void solve(){
cin >> n >> s;
s = ' '+s;
ll low = 1, high = (n/3);
ll ans = 0;
while(low <= high){
ll mid = ((low+high)/2);
if(check(mid*3)){
ans = mid*3;
low = mid+1;
}
else high = mid-1;
}
cout << ans;
}
int main(){
fast;
ll tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |