QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#766267#6299. Binary StringlyxWA 0ms3844kbC++141.2kb2024-11-20 16:47:202024-11-20 16:47:22

Judging History

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

  • [2024-11-20 16:47:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3844kb
  • [2024-11-20 16:47:20]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define rll register ll
#define ull unsigned ll
#define ri register int
#define fo(i,x,y) for(ri i=(x);i<=(y);++i)
#define fu(i,x,y) for(ri i=(x);i<(y);++i)
#define fd(i,x,y) for(ri i=(x);i>=(y);--i)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e7+5;
int T,mx[2],pi[N];string str;
inline void wt(ri x){
	if(x>9)wt(x/10);
	putchar(x%10+'0');
}
int main(){
//	std::ios::sync_with_stdio(0);
	scanf("%d",&T);
	while(T--){
		cin>>str;ri ln=str.size();
		ri w=ln;
		fu(i,0,ln){
			if(str[i]!=str[ln-1]){
				w=i;
				break;
			}
		}
		ri op=str[w]-'0';
		if(w==ln){
			puts("1");
			continue;
		}
//		printf("%d\n",w);
		fu(i,0,ln-w)str[i]=str[i+w];
		fu(i,ln-w,ln)str[i]=(op^1)+'0';
		mx[0]=mx[1]=0;
		ri la=0;
		fu(i,0,ln){
			if(i==ln-1||str[i]!=str[i+1]){
				ri o=str[i]-'0';
				mx[o]=max(mx[o],i-la+1);
				la=i+1;
			}
		}
		fd(i,ln,1)str[i]=str[i-1];
		pi[1]=0;str[0]='#';
		fo(i,2,ln){
			ri j=pi[i-1];
			while(j&&str[j+1]!=str[i])j=pi[j];
			pi[i]=j+(str[j+1]==str[i]);
		}
		ri s=min(mx[0],mx[1]);
		if(mx[1]<mx[0])++s;
		s+=ln-pi[ln];
		wt(s-1);putchar('\n');
	}
}
//110100000000000000

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3844kb

input:

3
1
001001
0001111

output:

1
4
9

result:

wrong answer 2nd numbers differ - expected: '3', found: '4'