QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359995#6299. Binary StringwdnmdwrnmmpWA 133ms3844kbC++141.6kb2024-03-21 08:51:202024-03-21 08:51:20

Judging History

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

  • [2024-03-21 08:51:20]
  • 评测
  • 测评结果:WA
  • 用时:133ms
  • 内存:3844kb
  • [2024-03-21 08:51:20]
  • 提交

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';
		return;
	}
	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();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

input:

3
1
001001
0001111

output:

1
3
9

result:

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

Test #2:

score: -100
Wrong Answer
time: 133ms
memory: 3544kb

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 512th numbers differ - expected: '10', found: '20'