QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303604 | #6299. Binary String | ucup-team052# | WA | 96ms | 5864kb | C++14 | 1.8kb | 2024-01-12 19:58:43 | 2024-01-12 19:58:43 |
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';
}
}
/*rep(i,1,n)putchar(t[i]);
puts("");*/
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;
}
printf("%d\n",n-nxt[n]+max(0,ret-1));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5748kb
input:
3 1 001001 0001111
output:
1 3 9
result:
ok 3 number(s): "1 3 9"
Test #2:
score: -100
Wrong Answer
time: 96ms
memory: 5864kb
input:
262144 000000000000000000 100000000000000000 010000000000000000 110000000000000000 001000000000000000 101000000000000000 011000000000000000 111000000000000000 000100000000000000 100100000000000000 010100000000000000 110100000000000000 001100000000000000 101100000000000000 011100000000000000 11110000...
output:
1 18 17 17 16 18 19 18 15 18 17 17 18 17 18 17 14 18 17 17 16 18 19 18 17 19 19 18 20 18 19 18 13 18 17 17 16 18 19 18 15 18 17 17 18 17 18 17 16 19 18 17 18 17 18 17 19 18 18 17 19 17 18 17 12 18 17 17 16 18 19 18 15 18 17 17 18 17 18 17 14 18 17 17 16 18 19 18 17 19 19 18 20 18 19 18 15 19 18 17 1...
result:
wrong answer 3rd numbers differ - expected: '18', found: '17'