QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#741058 | #6299. Binary String | louhao088 | WA | 163ms | 9788kb | C++98 | 1.4kb | 2024-11-13 13:10:53 | 2024-11-13 13:10:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXT=1e6,MAXN=1e7;
int T,n,ans;
string s;
int stk[MAXN+5],tp,tmp[MAXN+5],tot;
int A[MAXN+5],kmp[MAXN+5];
inline int nxt(int x) {return (x+1)*(x<n-1);}
inline int lst(int x) {return x-1+(!x)*n;}
inline int plu(int a,int b) {return a+b-(a+b>=n)*n;}
inline int sub(int a,int b) {return a-b+(a<b)*n;}
int main()
{
ios::sync_with_stdio(false);
cin>>T;
while(T--)
{
cin>>s,n=s.length();
if(n==1) {cout<<1<<endl;continue;}
ans=tp=tot=0;
for(int i=0;i<n;i++)
if(s[lst(i)]=='1' && s[i]=='1') stk[++tp]=i;
else if(s[i]=='0' && s[nxt(i)]=='0')
{
if(tp) ans=max(ans,((i-stk[tp--]+1)>>1));
else tmp[++tot]=i;
}
reverse(tmp+1,tmp+tot+1);
while(tp && tot) ans=max(ans,((n-stk[tp--]+tmp[tot--]+1)>>1));
for(int i=0;i<n;i++) A[i]=-1;
for(int i=1;i<=tp;i++) A[plu(stk[i],ans)]=1;
for(int i=1;i<=tot;i++) A[sub(tmp[i],ans)]=0;
if(!tp && !tot) {cout<<ans+2<<endl;continue;}
for(int i=0;i<n;i++)
if(A[i]==0)
{
bool v=0;
for(int j=nxt(i);A[j]<0;j=nxt(j)) A[j]=v,v^=1;
}
else if(A[i]==1)
{
bool v=1;
for(int j=lst(i);A[j]<0;j=lst(j)) A[j]=v,v^=1;
}
for(int i=1;i<n;i++)
{
kmp[i]=kmp[i-1];
while(kmp[i] && A[kmp[i]]^A[i]) kmp[i]=kmp[kmp[i]-1];
kmp[i]+=(A[kmp[i]]==A[i]);
}
cout<<ans+n-kmp[n-1]<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9780kb
input:
3 1 001001 0001111
output:
1 3 9
result:
ok 3 number(s): "1 3 9"
Test #2:
score: -100
Wrong Answer
time: 163ms
memory: 9788kb
input:
262144 000000000000000000 100000000000000000 010000000000000000 110000000000000000 001000000000000000 101000000000000000 011000000000000000 111000000000000000 000100000000000000 100100000000000000 010100000000000000 110100000000000000 001100000000000000 101100000000000000 011100000000000000 11110000...
output:
1 18 17 17 16 18 19 18 15 18 17 18 18 17 18 17 14 18 17 17 16 18 18 17 17 16 19 17 20 18 19 18 13 18 17 17 16 18 19 17 15 18 17 17 20 18 19 18 16 15 19 17 18 17 19 18 19 17 18 18 19 17 18 17 12 18 17 17 16 18 19 18 15 18 17 18 18 17 19 18 14 18 17 17 16 18 19 18 19 17 18 18 19 17 18 17 15 14 19 17 1...
result:
wrong answer 3rd numbers differ - expected: '18', found: '17'