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<cstdio>
#include<algorithm>
std::pair<std::pair<int,int>,int> a[200001];
char s[200002];
int main()
{
int max=0;
int i,j,n;
scanf("%d%s",&n,s+1);
for(i=1;i<=n;i++)
{
a[i].first=a[i-1].first;
if(s[i]=='J')
{
a[i].first.first++;
a[i].first.second++;
}
else if(s[i]=='O')a[i].first.first--;
else a[i].first.second--;
a[i].second=i;
}
std::sort(a,a+n+1);
i=j=0;
while(i<=n)
{
while(j<=n&&a[i].first==a[j].first)j++;
if(max<a[j-1].second-a[i].second)max=a[j-1].second-a[i].second;
i=j;
}
printf("%d",max);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |