Submission #173430

#TimeUsernameProblemLanguageResultExecution timeMemory
173430easruiJOIOJI (JOI14_joioji)C++14
100 / 100
63 ms6276 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; map<ll,int> M; ll N,J,O,I,cnt; int ans; string S; int main() { ios_base::sync_with_stdio(0),cin.tie(0); cin >> N >> S; M.insert(make_pair(0,0)); for(int i=0; i<N; i++){ if(S[i]=='J') O--,I--; if(S[i]=='O') O++; if(S[i]=='I') I++; cnt = O*(N+1)+I; if(M.find(cnt)==M.end()) M.insert(make_pair(cnt,i+1)); } for(int i=N-1; i>=0; i--){ cnt = O*(N+1)+I; if(M.find(cnt)!=M.end()) ans = max(ans,i+1-M[cnt]); if(S[i]=='J') O++,I++; if(S[i]=='O') O--; if(S[i]=='I') I--; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...