This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |