QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#96010#6299. Binary Stringwilliam555WA 90ms11812kbC++141.1kb2023-04-12 20:50:422023-04-12 20:50:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-12 20:50:46]
  • 评测
  • 测评结果:WA
  • 用时:90ms
  • 内存:11812kb
  • [2023-04-12 20:50:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e7+5;
int n,m,a[N],b[N],c[N],fail[N];
char s[N];
void solve(){
    scanf("%s",s+1),n=strlen(s+1);
    int cnt0=0;
    for(int i=1;i<=n;i++)cnt0+=s[i]=='0';
    if(cnt0<n-cnt0){
        cnt0=n-cnt0;
        reverse(s+1,s+n+1);
        for(int i=1;i<=n;i++)s[i]^=1;
    }
    if(cnt0==n){
        puts("1");
        return;
    }
    m=1;a[1]=0;
    for(int i=1;i<=n;i++){
        if(s[i]=='1')m++,a[m]=0;
        else a[m]++;
    }
    if(m>1)a[1]+=a[m],m--;
    int pos=1,mx=0;
    for(int i=1,s=0;i<=m;i++){
        s+=a[i]-1;
        if(s>mx)mx=s,pos=i;
    }
    pos=pos%m+1;
    for(int i=1,j=pos;i<=m;i++,j=j%m+1)b[i]=a[j];
    int ans=0;
    for(int i=1,s=0;i<=m;i++){
        s+=b[i]-1;
        ans=max(ans,-s);
        if(s>0)c[i]=s+1,s=0;
        else c[i]=1;
    }
    for(int i=2,j=0;i<=m;i++){
        while(j&&c[j+1]!=c[i])j=fail[j];
        if(c[j+1]==c[i])j++;
        fail[i]=j;
    }
    int k=m-fail[m];
    if(m%k)k=m;
    ans+=n/(m/k);
    printf("%d\n",ans);
}
int main(){
    int T;scanf("%d",&T);
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 11812kb

input:

3
1
001001
0001111

output:

1
3
9

result:

ok 3 number(s): "1 3 9"

Test #2:

score: -100
Wrong Answer
time: 90ms
memory: 9720kb

input:

262144
000000000000000000
100000000000000000
010000000000000000
110000000000000000
001000000000000000
101000000000000000
011000000000000000
111000000000000000
000100000000000000
100100000000000000
010100000000000000
110100000000000000
001100000000000000
101100000000000000
011100000000000000
11110000...

output:

1
18
18
19
18
18
19
20
18
18
18
19
19
19
20
21
18
18
18
19
18
18
19
20
19
19
19
20
20
20
21
22
18
18
18
19
18
18
19
20
18
18
18
19
19
19
20
21
19
19
19
19
19
19
20
21
20
20
20
21
21
21
22
23
18
18
18
19
18
18
19
20
18
18
18
19
19
19
20
21
18
18
18
19
18
18
19
20
19
19
19
20
20
20
21
22
19
19
19
19
1...

result:

wrong answer 12th numbers differ - expected: '20', found: '19'