Submission #156051

#TimeUsernameProblemLanguageResultExecution timeMemory
156051user202729JOIOJI (JOI14_joioji)C++17
100 / 100
47 ms6136 KiB
#include<iostream> #include<string> #include<map> int main(){ std::ios::sync_with_stdio(0);std::cin.tie(0); int n;std::cin>>n; std::string s;s.reserve(n);std::cin>>s; std::map<std::pair<int,int>,int> minpos; minpos.insert({{0,0},-1}); std::pair<int,int> cur; // {J-I, O-I} count int ans=0; for(int i=0;i<n;++i){ switch(s[i]){ case 'J':++cur.first;break; case 'O':++cur.second;break; case 'I':--cur.first;--cur.second;break; default:__builtin_unreachable(); } auto iter=minpos.find(cur); if(iter!=end(minpos))ans=std::max(ans,i-iter->second); minpos.insert({cur,i}); } std::cout<<ans<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...