QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#96009 | #6299. Binary String | william555 | WA | 84ms | 11764kb | C++14 | 1.1kb | 2023-04-12 20:48:08 | 2023-04-12 20:48:12 |
Judging History
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(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: 11764kb
input:
3 1 001001 0001111
output:
1 3 9
result:
ok 3 number(s): "1 3 9"
Test #2:
score: -100
Wrong Answer
time: 84ms
memory: 9796kb
input:
262144 000000000000000000 100000000000000000 010000000000000000 110000000000000000 001000000000000000 101000000000000000 011000000000000000 111000000000000000 000100000000000000 100100000000000000 010100000000000000 110100000000000000 001100000000000000 101100000000000000 011100000000000000 11110000...
output:
1 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 1...
result:
wrong answer 4th numbers differ - expected: '19', found: '10'