QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#96008#6299. Binary Stringwilliam555WA 85ms9900kbC++141.1kb2023-04-12 20:45:062023-04-12 20:45:09

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:45:09]
  • 评测
  • 测评结果:WA
  • 用时:85ms
  • 内存:9900kb
  • [2023-04-12 20:45:06]
  • 提交

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){
        reverse(s+1,s+n+1);
        for(int i=1;i<=n;i++)s[i]^=1;
    }
    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(s[j+1]==s[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: 0ms
memory: 9900kb

input:

3
1
001001
0001111

output:

1
3
9

result:

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

Test #2:

score: -100
Wrong Answer
time: 85ms
memory: 9760kb

input:

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

output:

18
18
18
10
18
18
19
20
18
18
18
19
10
19
20
21
18
18
18
19
9
18
19
20
10
19
19
20
20
20
21
22
18
18
18
19
9
18
19
20
9
18
18
19
19
19
20
21
10
19
19
19
19
19
20
21
20
20
20
21
21
21
22
23
18
18
18
19
9
18
19
20
9
18
18
19
19
19
20
21
9
18
18
19
18
18
19
20
19
19
19
20
20
20
21
22
10
19
19
19
19
19
...

result:

wrong answer 1st numbers differ - expected: '1', found: '18'