FHXZ @ 2016-08-05 17:31:47
炸死我了。。。这是个环吗?为什么只有50分?其他几个点都少了2,为什么?求大神解释!
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
int sum[1000005*2];
int len,ans=0,n;
int a[1000005*2];
char s[1000005*2];
int cnt1[1000005*2];
int cnt2[1000005*2];
int main()
{
scanf("%s",s+1);
n=strlen(s+1);
memset(cnt1,0,sizeof(cnt1));
memset(cnt2,0,sizeof(cnt2));
memset(sum,0,sizeof(sum));
memset(a,0,sizeof(a));
for (int i=1;i<=n;i++)
{
if(s[i]=='G')
a[i]=1;
else a[i]=-1;
}
for (int i=1;i<=n;i++)
{
sum[i]=sum[i-1]+a[i];
}
for (int i=1;i<=n;i++)
{
if(cnt1[sum[i]+n]==0)
cnt1[sum[i]+n]=i;
}
for (int i=n;i>=1;i--)
{
if(cnt2[sum[i]+n]==0)
cnt2[sum[i]+n]=i;
}
for (int i=0;i<=2*n+1;i++)
{
if(cnt1[i]!=0&&cnt2[i]!=0)
ans=max(ans,cnt2[i]-cnt1[i]);
}
printf("%d\n",ans);
return 0;
}
by 据设错了 @ 2018-07-07 10:06:34
。。。