QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#467327 | #1289. A + B Problem | Nephren_Sakura | RE | 0ms | 0kb | C++14 | 1.2kb | 2024-07-08 15:48:24 | 2024-07-08 15:48:24 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int t,n,m,a[2000005];
int b[1000005],c[1000005];
int ans[1000005];
stack<int> stk;
signed main(){
freopen("partition.in","r",stdin);
freopen("partition.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>t;
while(t--){
cin>>n>>m;
int s=0;
for(int i=1; i<=n+m; i++){
char c;
cin>>c;
a[i]=c-'0';
s+=a[i];
}
if(n>m) swap(n,m);
int nwb=n,nwc=m;
for(int i=1; i<=n; i++){
b[--nwb]=a[i];
if(a[i]) stk.push(nwb);
}
for(int i=1; i<=m; i++){
if(a[n+i]==1) c[--nwc]=a[n+i];
else if(stk.empty()==false&&nwc-1>stk.top()){
c[--nwc]=1;
b[stk.top()]=0;
stk.pop();
}
else
c[--nwc]=0;
}
while(!stk.empty()) stk.pop();
for(int i=0; i<max(n,m)+1; i++){
ans[i]+=b[i]+c[i];
ans[i+1]+=ans[i]/2;
ans[i]%=2;
}
for(int i=0; i<n; i++)
b[i]=0;
for(int i=0; i<m; i++)
c[i]=0;
bool f=false;
for(int i=max(n,m); i>=0; i--){
if(ans[i]){
cout<<ans[i];
f=true;
}
else if(f)
cout<<ans[i];
ans[i]=0;
}
if(!f) cout<<0;
cout<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
3 4 3 1000101 2 2 1111 1 1 00