QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359994#6299. Binary StringwdnmdwrnmmpWA 0ms3544kbC++141.6kb2024-03-21 08:51:002024-03-21 08:51:01

Judging History

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

  • [2024-03-21 08:51:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3544kb
  • [2024-03-21 08:51:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int> vi;
typedef pair<int,int> pi;

void solve(){
	string s; cin>>s;
	int n=s.size();
	int cnt0=0;
	for(char c:s){
		cnt0+=(c=='0');
	}
	if(cnt0==0 || cnt0==n){
		cout<<1<<'\n';
	}
	if(cnt0>n-cnt0){
		reverse(s.begin(),s.end());
		for(char &c:s){
			c^=1;
		}
	}
	string tmp;
	rep(i,0,n-1){
		if(s[i]=='1'){
			tmp+=s.substr(i+1,n-(i+1));
			tmp+=s.substr(0,i+1);
			swap(s,tmp);
			break;
		}
	}
	vi a;
	int cnt=0;
	rep(i,0,n-1){
		if(s[i]=='0'){
			cnt++;
		}
		else{
			a.pb(cnt);
			cnt=0;
		}
	}
	a.insert(a.end(),a.begin(),a.end());
	vi b(a.size());
	int ans=0,cur=0,clen=0;
	per(i,(int)a.size()-1,0){
		cur+=a[i];
		b[i]=(cur>0);
		cur--;
		if(cur<=0){
			cur=0,clen=0;
		}
		else{
			clen++;
			ans=max(ans,clen);
		}
	}
	string t;
	rep(i,0,(int)b.size()/2-1){
		rep(_,1,b[i]){
			t+='0';
		}
		t+='1';
	}
	vi kmp(t.size(),-1);
	rep(i,1,(int)t.size()-1){
		kmp[i]=kmp[i-1];
		while(kmp[i]!=-1 && t[i]!=t[kmp[i]+1]){
			kmp[i]=kmp[kmp[i]];
		}
		if(t[i]==t[kmp[i]+1]){
			kmp[i]++;
		}
	}
	int cr=0,L=kmp.back();
	while(L!=-1){
		if(n%(n-(L+1))==0){
			cr=n-(L+1);
		}
		L=kmp[L];
	}
	ans=ans+(t.size()-cr);
	cout<<ans<<'\n';
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	int t; cin>>t;
	while(t--){
		solve();
	}
}

詳細信息

Test #1:

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

input:

3
1
001001
0001111

output:

1
1
3
9

result:

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