QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#390176#6299. Binary StringNATURAL6WA 0ms10020kbC++142.3kb2024-04-15 09:26:272024-04-15 09:26:28

Judging History

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

  • [2024-04-15 09:26:28]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:10020kb
  • [2024-04-15 09:26:27]
  • 提交

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];
inline int qread(char *c)
{
    int len=0;
    char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))c[++len]=ch,ch=getchar();
    return len;
}
signed main()
{
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
    T=qread();
    while(T--)
    {
        n=qread(ch);ans=cnt0=cnt1=ed=mn=pos=0;ch[n+1]=0;
        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];
                for(int j=1;j<=n;++j)swap(S[j],ch[j]);
				break;
            }
        }
        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=0;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];
        for(int i=1;i<=ed;++i)que[i]=A[i];
        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;
            else kmp[i]=0;
        }
        if(n%(n-kmp[n])==0)ans+=(n-kmp[n]);
        else ans+=n;
        printf("%d %d\n",ans,T);
    }
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 10020kb

input:

3
1
001001
0001111

output:

1 2
3 1
9 0

result:

wrong answer 2nd numbers differ - expected: '3', found: '2'