Submission #674814

#TimeUsernameProblemLanguageResultExecution timeMemory
674814sudheerays123JOIOJI (JOI14_joioji)C++17
0 / 100
2 ms328 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...