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