QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361099 | #6299. Binary String | D_F_S | WA | 101ms | 11472kb | C++14 | 2.1kb | 2024-03-22 19:41:34 | 2024-03-22 19:41:34 |
Judging History
answer
#include<bits/stdc++.h>
#define inl inline
using namespace std;
const int N=1e7+5,P=998244353,IB=1<<21; char IN[IB],*IS=IN+IB,*IT=IS;
#define getchar() (IS==IT&&(fread(IS=IN,1,IB,stdin)),*IS++)
struct B {int l,r,t; }b[N];
int T,n,an,bc,a[N*2],ca[2],ne[N*2];
inl int Read()
{
int s=0; char c; while(!isdigit(c=getchar()));
for(;isdigit(c);c=getchar()) s=s*10+c-'0'; return s;
}
inl void Reas()
{
char c; while(!isdigit(c=getchar()));
for(n=0;isdigit(c);a[++n]=c-'0',c=getchar());
}
int main()
{
//~ freopen("a.in","r",stdin);
//~ freopen("mine.out","w",stdout);
for(int T=Read();T--;printf("%d\n",an))
{
Reas(); int t=1; for(a[n+1]=!a[1];a[t]==a[1];++t);
if(t>n) {an=1; continue; } rotate(a+1,a+t,a+n+1); ca[0]=ca[1]=1;
for(int l=1,r;l<=n;ca[a[l]]+=r-l,l=r+1) for(r=l;r<n&&(a[r+1]==a[l]);++r);
if(ca[1]<ca[0]) {reverse(a+1,a+n+1); for(int i=1;i<=n;++i) a[i]=!a[i]; }
t=0; for(int i=1,j=0,k=0;i<=n;++i) (j+=a[i]?1:-1)<k&&(k=j,t=i);
rotate(a+1,a+t+1,a+n+1); bc=an=0;
//~ for(int i=1;i<=n;++i) cerr<<" "<<a[i]; cerr<<"\n";
for(int l=1,r;l<=n;l=r+1)
{
for(r=l;r<n&&(a[r+1]==a[l]);++r); if(l==r) continue;
if(a[l]==1) {b[++bc]={l,r,0}; continue; }
int tl=l,tr=r,t=0; while(tl<tr)
{
assert(bc);
int &bl=b[bc].l,&br=b[bc].r,&bt=b[bc].t,d;
t<bt?(tl-=bt-t,tr-=bt-t,t=bt):(bl+=t-bt,br+=t-bt,bt=t);
assert(br<tl);
d=(tl-br)/2; tl-=d; tr-=d; t+=d; bl+=d; br+=d; bt+=d;
d=min(tr-tl,br-bl); tr-=d; t+=d; bl+=d; bt+=d; bl==br&&(--bc);
}
an=max(an,t);
}
//~ cerr<<an<<"\n";
t=n; fill(a+1,a+n+1,0); for(int i=1;i<=bc;++i)
{
int d=an-b[i].t,l=b[i].l+d,r=b[i].r+d; l>n&&(l-=n); r>n&&(r-=n);
//~ cerr<<"^^ "<<l<<" "<<r<<"\n";
t=min(t,l); l<r?fill(a+l,a+r+1,1):(fill(a+l,a+n+1,1),fill(a+1,a+r+1,1));
}
for(int i=t-1,j=1;i;a[i--]=j^=1); for(int i=2;i<=n;++i) !a[i-1]&&(a[i]=1);
//~ for(int i=1;i<=n;++i) cerr<<" "<<a[i]; cerr<<"\n";
for(int i=1;i<=n;++i) a[n+i]=a[i];
for(int i=2,j=0;i<=n*2;ne[i]=j+=a[i]==a[j+1],++i)
{
for(;j&&a[i]!=a[j+1];j=ne[j]);
}
an+=n*2-ne[n*2];
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10012kb
input:
3 1 001001 0001111
output:
1 3 9
result:
ok 3 number(s): "1 3 9"
Test #2:
score: -100
Wrong Answer
time: 101ms
memory: 11472kb
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 20 19 19 20 21 18 18 18 19 18 18 20 21 19 19 19 21 20 20 21 22 18 18 18 19 18 18 19 21 18 18 18 21 20 20 21 22 19 19 19 19 19 19 21 22 20 20 20 22 21 21 22 23 18 18 18 19 18 18 19 20 18 18 18 20 19 19 21 22 18 18 18 19 18 18 21 22 20 20 20 22 21 21 22 23 19 19 19 19 1...
result:
wrong answer 4034th numbers differ - expected: '23', found: '7'