QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#95453#6299. Binary StringwyzwyzCompile Error//C++142.4kb2023-04-09 19:22:412023-04-09 19:23:17

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:17]
  • 评测
  • [2023-04-09 19:22:41]
  • 提交

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

详细

answer.code: In function ‘int main()’:
answer.code:122:12: error: ‘t’ was not declared in this scope
  122 |         if(t>3){
      |            ^
answer.code: In function ‘void work()’:
answer.code:37:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |         scanf("%s",StR+1);
      |         ~~~~~^~~~~~~~~~~~