QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#359995 | #6299. Binary String | wdnmdwrnmmp | WA | 133ms | 3844kb | C++14 | 1.6kb | 2024-03-21 08:51:20 | 2024-03-21 08:51:20 |
Judging History
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();
}
}
详细
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'