Submission #152589

#TimeUsernameProblemLanguageResultExecution timeMemory
152589oolimryJOIOJI (JOI14_joioji)C++14
100 / 100
76 ms6272 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int I = 0; int J = 0; int O = 0; typedef pair<int,int> ii; map<ii,int> m; for(int i = 0;i < n;i++){ if(s[i] == 'I') I++; else if(s[i] == 'O') O++; else J++; m[ii(O-J,O-I)] = i; } I = 0, J = 0, O = 0; int ans = 0; for(int i = 0;i < n;i++){ if(m.find(ii(O-J,O-I)) != m.end() && m[ii(O-J,O-I)] > i) ans = max(ans,m[ii(O-J,O-I)] - i + 1); if(s[i] == 'I') I++; else if(s[i] == 'O') O++; else J++; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...