This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma warning(disable:4996)
#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
char p[200010];
struct A{
int a, b, ord;
bool operator <(const A &p)const{
return a != p.a ? a < p.a : b != p.b ? b < p.b : ord < p.ord;
}
}w[200010];
int main()
{
int i, t, M = 0;
scanf("%d", &n);
scanf("%s", p + 1);
for (i = 1; i <= n; i++){
w[i] = w[i - 1];
if (p[i] == 'J')w[i].a++, w[i].b++;
else if (p[i] == 'O')w[i].a--;
else w[i].b--;
w[i].ord = i;
}
sort(w, w + n + 1);
for (i = 0; i <= n; i++){
if (i && w[i].a == w[i - 1].a && w[i].b == w[i - 1].b){
if (M < w[i].ord - t)M = w[i].ord - t;
}
else{
t = w[i].ord;
}
}
printf("%d\n", M);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |