QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#831262 | #1289. A + B Problem | lyx | WA | 5ms | 23916kb | C++14 | 2.7kb | 2024-12-25 12:20:49 | 2024-12-25 12:20:49 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define rll register 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=2e6+5;
int T,n,m,a[2][N],k[2],la[N],ar[N],b[N],ans[N];
int jl[2][N],pre[N];
inline void air(){}
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
template <typename T>inline void read(T& r) {
r=0;bool w=0; char ch=getchar();
while(ch<'0'||ch>'9') w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9') r=r*10+(ch^48), ch=getchar();
r=w?-r:r;
}
inline int read(){
register char ch=getchar();
while(ch<'0'||ch>'1')ch=getchar();
return ch-'0';
}
inline int bj(){
if(jl[0][0]>jl[1][0]){
return 1;
}
if(jl[0][0]<jl[1][0])return 0;
fd(i,b[0],1){
if(jl[0][i]>jl[1][i]){
return 1;
}
if(jl[0][i]<jl[1][i])return 0;
}
return 2;
}
inline void get(){
ans[0]=b[0];
fo(i,1,b[0])ans[i]=b[i];
}
inline void upd(){
if(b[0]>ans[0]){
get();
return;
}
if(b[0]<ans[0])return;
fd(i,b[0],1){
if(b[i]>ans[i]){
get();
return;
}
if(b[i]<ans[i])return;
}
}
inline void check(ri st,ri op){
if(st<0||st>m)return;
fo(i,1,max(n,m)+1)a[0][i]=a[1][i]=b[i]=0;
k[0]=n;k[1]=m;
fo(i,1,st)a[1][k[1]--]=ar[i];
fo(i,st+1,n+m){
if(!k[0])a[1][k[1]--]=ar[i];
else if(!k[1])a[0][k[0]--]=ar[i];
else{
ri nw=k[1]>k[0];
if(k[nw^1]>=la[i]-i){
a[nw][k[nw]--]=1;
fo(j,1,la[i]-i)a[nw^1][k[nw^1]--]=0;
i=la[i];
}
else{
a[nw][k[nw]--]=0;
}
}
}
fo(i,1,max(n,m)){
b[i]+=a[0][i]+a[1][i];
b[i+1]+=b[i]/2;b[i]&=1;
}
b[0]=1;
fd(i,max(n,m)+1,1){
if(b[i]){b[0]=i;break;}
}
fo(i,0,b[0])jl[op][i]=b[i];
upd();
}
int main(){
scanf("%d",&T);
ri js=0;
while(T--){
read(n);read(m);
if(n<m)swap(n,m);
fo(i,1,n+m){
ar[i]=read();
pre[i]=ar[i]?i:pre[i-1];
}
ri La=n+m+1;la[n+m+1]=La;
fd(i,n+m,1){
if(ar[i])La=i;la[i]=La;
}
ans[0]=0;
++js;
if(js==6607){
printf("%d %d\n",n,m);
fo(i,1,n+m){
printf("%d",ar[i]);
}
return 0;
}
ri l=0,r=m;
while(l<=r){
ri md=l+r>>1;
jl[0][0]=jl[1][0]=0;
check(md-1,0);
check(pre[md-1],0);
check(md+1,0);
check(md,0);check(la[md+1],1);
ri o=bj();
if(o==2){
if(ar[md+1])l=md+1;
else r=md-1;
}
else if(o){
r=md-1;
}
else{
l=md+1;
}
}
if(T<100){
fd(i,ans[0],1)putchar(ans[i]+'0');
puts("");
}
}
cerr<<endl<<endl<<"time:"<<(double)clock()/CLOCKS_PER_SEC<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 22256kb
input:
3 4 3 1000101 2 2 1111 1 1 00
output:
1101 110 0
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 5ms
memory: 23916kb
input:
11110 10 8 111011010011100100 3 5 01011000 7 6 1110101010000 9 1 0110100101 1 9 0100001110 8 10 000101101011111000 9 6 011111111000111 1 9 1011101101 10 7 00100011000100000 4 9 1000101101010 8 4 100100110000 8 9 00101111011000101 8 9 11000000101011110 7 6 1111010100110 2 9 01001110101 4 5 100010100 ...
output:
10 9 1000011111111011011
result:
wrong answer 1st lines differ - expected: '10011010100', found: '10 9'