QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#390147#6299. Binary StringNATURAL6WA 31ms103440kbC++142.0kb2024-04-15 08:50:322024-04-15 08:50:32

Judging History

你现在查看的是最新测评结果

  • [2024-04-15 08:50:32]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:103440kb
  • [2024-04-15 08:50:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
inline int qread()
{
    int a=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){(a*=10)+=(ch^48);ch=getchar();}
    return a*f;
}
int T,n,ans,cnt0,cnt1,que[10000010],ed,mn,pos,A[10000010],kmp[10000010];
char ch[10000010],S[10000010];
signed main()
{
    T=qread();
    while(T--)
    {
        scanf("%s",ch+1);ans=0;
        cnt0=cnt1=0;n=strlen(ch+1);
        for(int i=1;i<=n;++i)
        {
            if(ch[i]=='0')++cnt0;
            else ++cnt1;
        }
        if(cnt0<cnt1)
        {
            for(int i=1;i<=n;++i)ch[i]^=1;
            reverse(ch+1,ch+1+n);swap(cnt0,cnt1);
        }
        for(int i=1;i<=n;++i)
        {
            if(ch[i]=='0')
            {
                for(int j=1;j<=n;++j)S[j]=ch[(i+j-2)%n+1];
                swap(ch,S);break;
            }
        }
        ed=mn=pos=0;
        for(int l=1,r;l<=n;l=r)
        {
            r=l+1;
            while(r<=n&&ch[r]=='1')++r;
            que[++ed]=r-l-1;
        }
        for(int i=1,sum;i<=ed;++i)
        {
            sum+=que[i]-1;
            if(sum<mn)mn=sum,pos=i;
        }
        for(int i=1;i<=ed;++i)A[i]=que[(i+pos-1)%ed+1];
        swap(A,que);
        for(int i=1,sum,cnt,j;i<=ed;++i)
        {
            if(que[i]<=1)continue;
            j=i,sum=0,cnt=0;
            while(1)
            {
                sum+=que[j]-1;
                if(sum<=0)break;
                ++j;++cnt;
            }
            ans=max(ans,cnt);
            for(int k=i;k<=j;++k)que[k]=1;
        }
        n=0;
        for(int i=1;i<=ed;++i)
        {
            ch[++n]='0';
            if(que[i]==1)ch[++n]='1';
        }
        for(int i=2,j;i<=n;++i)
        {
            j=kmp[i-1];
            while(j&&ch[i]^ch[j+1])j=kmp[j];
            if(ch[i]==ch[j+1])kmp[i]=j+1;
        }
        if(n%(n-kmp[n])==0)ans+=(n-kmp[n]);
        else ans+=n;
        printf("%d\n",ans);
    }
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 31ms
memory: 103440kb

input:

3
1
001001
0001111

output:

1
3
7

result:

wrong answer 3rd numbers differ - expected: '9', found: '7'