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 <bits/stdc++.h>
#define int long long
using namespace std;
map<int, int> a;
int n;
string s;
int hashed[200005];
int cj, co, ci;
int lel(int x, int y, int z)
{
int ax=min(x, min(y,z));
x-=ax, y-=ax, z-=ax;
return x*200000*200000+y*200000+z;
}
signed main()
{
cin>>n;
cin>>s;
for(int i=0; i<n; i++)
{
if(s[i]=='J')
{
cj++;
}
if(s[i]=='O')
{
co++;
}
if(s[i]=='I')
{
ci++;
}
hashed[i]=lel(ci,co,cj);
a[hashed[i]]=1000000000;
}
for(int i=n-1; i>=0; i--)
{
a[hashed[i]]=min(a[hashed[i]], i);
}
a[0]=-1;
int ans=0;
for(int i=0; i<n; i++)
{
ans=max(ans, i-a[hashed[i]]);
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |