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<stdio.h>
#include<map>
using namespace std;
#define X first
#define Y second
typedef pair<int,int> Pi;
char ch[200020];
int n, ans;
map <Pi, int> M;
int main(){
scanf("%d%s",&n,ch);
Pi now = Pi(0,0);
M[Pi(0,0)] = -1;
for(int i=0;ch[i];i++){
if(ch[i] == 'J')--now.X, --now.Y;
else if(ch[i] == 'I')++now.X;
else ++now.Y;
if(M.find(now) != M.end())ans = max(ans, i - M[now]);
else M[now] = i;
}
printf("%d",ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |