QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#154746#6299. Binary String275307894aWA 84ms10036kbC++141.8kb2023-08-31 21:46:232023-08-31 21:46:23

Judging History

你现在查看的是最新测评结果

  • [2023-08-31 21:46:23]
  • 评测
  • 测评结果:WA
  • 用时:84ms
  • 内存:10036kb
  • [2023-08-31 21:46:23]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar() 
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e6+5,M=N*40+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,H,T,st[N],op[N],Nt[N];char s[N],c[N];
void Solve(){
	int i,j;scanf("%s",s+1);n=strlen(s+1);for(i=1;i<=n;i++) s[i]-='0';
	int C[2]={0,0};
	for(i=1;i<=n;i++) C[s[i]]++;
	if(C[0]<C[1]){
		for(i=1;i<=n;i++) s[i]^=1;
		swap(C[0],C[1]);
	} 
	if(!C[1]){puts("1");return;}
	for(i=1;i<=n;i++) if(!s[i]) {rotate(s+1,s+i,s+n+1);break;}
	st[T=1]=0;op[1]=0;
	for(i=1;i<=n;i++){
		if(!s[i]){
			if(op[T]==0) st[T]++;
			else st[++T]=1,op[T]=0;
		}else{
			if(!op[T]&&op[T-1]&&st[T-1]>st[T])st[T-1]++;
			else {
				if(op[T]==1) st[T]++;
				else st[++T]=1,op[T]=1;
			}
		}
	}
	if(!op[T]) st[1]+=st[T],T--;
	H=1;
	while(st[T]>st[H]) st[T]+=st[H+1],st[H+2]+=st[H],H+=2;
	// for(i=H;i<=T;i++) cerr<<st[i]<<' ';
	int ans=0;for(i=H+1;i<=T;i+=2) ans=max(ans,st[i]-1);
	int m=0;
	for(i=H;i<T;i+=2){
		for(j=1;j<=st[i]-st[i^H?i-1:T];j++) c[++m]='0';
		for(j=1;j<=st[i+1];j++) c[++m]='0',c[++m]='1';
	}
	Nt[1]=0;for(i=2;i<=m;i++){
		Nt[i]=Nt[i-1];while(Nt[i]&&c[i]^c[Nt[i]+1]) Nt[i]=Nt[Nt[i]];
		if(c[i]==c[Nt[i]+1]) Nt[i]++;
	}
	// cerr<<ans<<'\n';
	// cerr<<Nt[n]<<'\n';
	if(n%(n-Nt[n])==0) ans+=n-Nt[n];else ans+=n;
	printf("%d\n",ans);
}
int main(){
	int t;
	scanf("%d",&t);
	// t=1;
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 10036kb

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: 9916kb

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 1536th numbers differ - expected: '25', found: '24'