http://www.lydsy.com/JudgeOnline/problem.php?id=4236
智障就要多刷题;
%%%zyy
对于x,y,z
我们记录,x-y,y-z就好了
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#define pa pair<int,int>
#define Ll long long
using namespace std;
map<pa,int>F;
int n,ans,x,y,z;
char c;
int main()
{
scanf("%d",&n);
F[make_pair(0,0)]=1;
for(int i=2;i<=n+1;i++){
cin>>c;
if(c=='J')x++;else
if(c=='O')y++;else
if(c=='I')z++;
pa a=make_pair(x-y,y-z);
if(!F[a])F[a]=i;else ans=max(ans,i-F[a]);
}
printf("%d",ans);
}