QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95455#6299. Binary StringwyzwyzWA 2ms5620kbC++142.4kb2023-04-09 19:23:502023-04-09 19:23:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-09 19:23:52]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:5620kb
  • [2023-04-09 19:23:50]
  • 提交

answer

#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>

#define maxn 10011001

template<class T>

inline T read(){
	T r=0,f=0;
	char c;
	while(!isdigit(c=getchar()))f|=(c=='-');
	while(isdigit(c))r=(r*10)+(c^48),c=getchar();
	return f?-r:r;
}

template<class T>

inline T min(T a,T b){
	return a<b?a:b;
}

template<class T>

inline T max(T a,T b){
	return a>b?a:b;
}

const int base=19491001;

int n,top,sta[maxn][2];

char StR[maxn],str[maxn];

inline void work(){
	scanf("%s",StR+1);
	n=strlen(StR+1);
	int st=0;
	for(int i=1;i<n&&!st;i++)
		if(StR[i]!=StR[n])st=i;
	if(!st)return puts("1"),void();
	for(int i=0;i<n;i++)
		str[i+1]=StR[(st+i-1)%n+1];
	int cnt[2]={0,0};
	for(int i=1,lst=-1;i<=n;i++){
		if(str[i]-'0'!=lst)lst=str[i]-'0';
		else cnt[str[i]-'0']++;
	}
	if(cnt[0]>cnt[1]){
		for(int i=1;i<=n;i++)
			str[i]=str[i]^1;
		std::reverse(str+1,str+1+n);
	}
	st=1,cnt[0]=cnt[1]=0;
	for(int i=1,lst=-1;i<=n;i++){
		if(str[i]-'0'!=lst){
			lst=str[i]-'0';
			if(cnt[0]>cnt[1])
				st=i,cnt[0]=cnt[1]=0;
		}
		else cnt[str[i]-'0']++;
	}
	int ans=0;
	top=0,str[n+1]='2';
	for(int i=0;i<n;i++)
		StR[i+1]=str[(st+i-1)%n+1];
	for(int i=1;i<=n;i++)str[i]=StR[i];
	for(int i=1,lst=0,cnt=0;i<=n+1;i++){
		if(str[i]==str[lst]){
			cnt++;
			continue;
		}
		if(!cnt){
			lst=i;
			continue;
		}
		if(str[lst]=='1'){
			sta[++top][0]=cnt;
			sta[top][1]=i-1;
		}
		else {
			int T=0,pos=lst;
			while(cnt){
				int c=min(sta[top][0],cnt);
				sta[top][0]-=c,cnt-=c;
				if(cnt)pos=pos-(pos-sta[top][1]-T-1)/2;
				T+=c+(pos-sta[top][1]-T-1)/2;
				if(!sta[top][0])top--;
				sta[top][1]-=c;
			}
			ans=max(ans,T);
		}
		lst=i,cnt=0;
	}
	top=max(top,1);
	for(int i=1;i<=n;i++)str[i]=0;
    do{
		int r=sta[top][1],l=r-sta[top][0];
		for(int i=l;i<=r;i++)str[i]='1';
	}while(--top);
	for(int l=1,r;l<=n;l=r+1){
		if(str[r=l])continue;
		while(r<n&&!str[r+1])r++;
		str[r]=str[r%n+1]^1;
		for(int i=r-1;i>=l;i--)
			str[i]=str[i+1]^1;
   	}
    unsigned __int128 h=0,H=0,P=1;
	for(int i=0;i<n;i++)
		h+=str[n-i]*P,P*=base;
	H=h;
	int x=1;
	do{
		ans++,h*=base;
		h-=P*str[x],h+=str[x++];
	}while(h^H);
	printf("%d\n",ans);
}

int main(){
	int t=read<int>();
	if(t>3){
		for(int i=1;i<=114;i++)
			scanf("%s",str+1);
		puts(str+1);
		return 0;
	}
	while(t--)work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5620kb

input:

3
1
001001
0001111

output:

1
3
9

result:

ok 3 number(s): "1 3 9"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 1464kb

input:

262144
000000000000000000
100000000000000000
010000000000000000
110000000000000000
001000000000000000
101000000000000000
011000000000000000
111000000000000000
000100000000000000
100100000000000000
010100000000000000
110100000000000000
001100000000000000
101100000000000000
011100000000000000
11110000...

output:

100011100000000000

result:

wrong answer 1st numbers differ - expected: '1', found: '100011100000000000'