QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#766267 | #6299. Binary String | lyx | WA | 0ms | 3844kb | C++14 | 1.2kb | 2024-11-20 16:47:20 | 2024-11-20 16:47:22 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define rll register ll
#define ull unsigned ll
#define ri register int
#define fo(i,x,y) for(ri i=(x);i<=(y);++i)
#define fu(i,x,y) for(ri i=(x);i<(y);++i)
#define fd(i,x,y) for(ri i=(x);i>=(y);--i)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e7+5;
int T,mx[2],pi[N];string str;
inline void wt(ri x){
if(x>9)wt(x/10);
putchar(x%10+'0');
}
int main(){
// std::ios::sync_with_stdio(0);
scanf("%d",&T);
while(T--){
cin>>str;ri ln=str.size();
ri w=ln;
fu(i,0,ln){
if(str[i]!=str[ln-1]){
w=i;
break;
}
}
ri op=str[w]-'0';
if(w==ln){
puts("1");
continue;
}
// printf("%d\n",w);
fu(i,0,ln-w)str[i]=str[i+w];
fu(i,ln-w,ln)str[i]=(op^1)+'0';
mx[0]=mx[1]=0;
ri la=0;
fu(i,0,ln){
if(i==ln-1||str[i]!=str[i+1]){
ri o=str[i]-'0';
mx[o]=max(mx[o],i-la+1);
la=i+1;
}
}
fd(i,ln,1)str[i]=str[i-1];
pi[1]=0;str[0]='#';
fo(i,2,ln){
ri j=pi[i-1];
while(j&&str[j+1]!=str[i])j=pi[j];
pi[i]=j+(str[j+1]==str[i]);
}
ri s=min(mx[0],mx[1]);
if(mx[1]<mx[0])++s;
s+=ln-pi[ln];
wt(s-1);putchar('\n');
}
}
//110100000000000000
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3844kb
input:
3 1 001001 0001111
output:
1 4 9
result:
wrong answer 2nd numbers differ - expected: '3', found: '4'