This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 = 2e5+5 , INF = 1e18 , MOD = 1e9+7;
vector<char> s(N);
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;
for(ll i = 1; i <= n; i++) cin >> s[i];
ll low = 1, high = (n/3);
ll ans = 0;
while(low <= high){
ll mid = ((low+high)/2);
if(check(mid*3ll)){
ans = mid*3ll;
low = mid+1;
}
else high = mid-1;
}
cout << ans << "\n";
}
int main(){
fast;
ll tc = 1;
// cin >> tc;
while(tc--) solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |