Submission #152588

#TimeUsernameProblemLanguageResultExecution timeMemory
152588oolimryJOIOJI (JOI14_joioji)C++14
0 / 100
4 ms504 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(J-O,I-O)] = 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...