이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |