QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#303610 | #6299. Binary String | ucup-team052# | WA | 100ms | 3820kb | C++14 | 1.9kb | 2024-01-12 20:09:08 | 2024-01-12 20:09:08 |
Judging History
answer
#include<bits/stdc++.h>
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ "="),debug_helper::debug(__VA_ARGS__),D("\n")
#include"/home/xay5421/debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define each(x,v) for(auto&x:v)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
template<class T>void rd(T&x){int f=0,c;while(!isdigit(c=getchar()))f^=!(c^45);x=(c&15);while(isdigit(c=getchar()))x=x*10+(c&15);if(f)x=-x;}
template<class T>void pt(T x,int c=-1){if(x<0)putchar('-'),x=-x;if(x>9)pt(x/10);putchar(x%10+48);if(c!=-1)putchar(c);}
using namespace std;
using LL=long long;
using ULL=unsigned long long;
const int N=2000005;
int T,n,nxt[N];
char s[N],t[N];
int main(){
rd(T);
while(T--){
scanf("%s",s+1);
n=strlen(s+1);
if(count(s+1,s+n+1,'1')<count(s+1,s+n+1,'0')){
rep(i,1,n)s[i]^=1;
reverse(s+1,s+n+1);
}
int cur=0,ret=0;
rep(i,1,n){
cur=max(cur+(s[i]=='0'?1:-1),0);
ret=max(ret,cur);
}
rep(i,1,n){
cur=max(cur+(s[i]=='0'?1:-1),0);
ret=max(ret,cur);
}
int todo=0,last=0;
rep(i,1,n){
if(s[i]=='0')++todo;
if(todo>0){
if(last==1){
last=0;
--todo;
}else{
last=1;
}
}else{
last=1;
}
}
rep(i,1,n){
if(s[i]=='0')++todo;
if(todo>0){
if(last==1){
last=0;
t[i]='0';
--todo;
}else{
last=1;
t[i]='1';
}
}else{
last=1;
t[i]='1';
}
}
/*D("t:");
rep(i,1,n)D("%c",t[i]);
D("\n");*/
nxt[0]=nxt[1]=0;
int j=0;
rep(i,2,n){
while(j&&t[i]!=t[j+1])j=nxt[j];
if(t[i]==t[j+1])++j;
nxt[i]=j;
}
int t=n;
for(int i=nxt[n];;i=nxt[i]){
if(n%(n-i)==0){t=n-i;break;}
if(i==0)break;
}
printf("%d\n",t+max(0,ret-1));
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3820kb
input:
3 1 001001 0001111
output:
1 3 9
result:
ok 3 number(s): "1 3 9"
Test #2:
score: -100
Wrong Answer
time: 100ms
memory: 3644kb
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 19 19 19 20 21 18 18 18 19 18 18 19 20 19 19 19 20 20 20 21 22 18 18 18 19 18 18 19 20 18 18 18 19 19 19 20 21 19 19 19 19 19 19 20 21 20 20 20 21 21 21 22 23 18 18 18 19 18 18 19 20 18 18 18 19 19 19 20 21 18 18 18 19 18 18 19 20 19 19 19 20 20 20 21 22 19 19 19 19 1...
result:
wrong answer 12th numbers differ - expected: '20', found: '19'