QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#96008 | #6299. Binary String | william555 | WA | 85ms | 9900kb | C++14 | 1.1kb | 2023-04-12 20:45:06 | 2023-04-12 20:45:09 |
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){
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;
}
詳細信息
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'