Submission #612534

#TimeUsernameProblemLanguageResultExecution timeMemory
612534okkuuJOIOJI (JOI14_joioji)C++17
100 / 100
39 ms10428 KiB
#define _USE_MATH_DEFINES #include<iostream> #include<vector> #include<algorithm> #include<cmath> #include<string> #include<iomanip> #include<numeric> #include<queue> #include<deque> #include<stack> #include<set> #include<map> #include<random> #include<bitset> #include<cassert> using namespace std; typedef long long ll; const int mod=998244353; const int dx[]={1,0,0,-1},dy[]={0,1,-1,0}; int main(){ int n; string s; cin>>n>>s; map<pair<int,int>,vector<int>>mp; int x=0,y=0; mp[{x,y}].push_back(0); for(int i=0;i<n;i++){ if(s[i]=='J') x++; if(s[i]=='O') y++; if(s[i]=='I') x--,y--; mp[{x,y}].push_back(i+1); } int ans=0; for(auto&e:mp) if(e.second.size()>=2) ans=max(ans,e.second.back()-e.second[0]); cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...