QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#26505 | #1289. A + B Problem | Wu_Ren | WA | 69ms | 6248kb | C++17 | 707b | 2022-04-07 15:56:18 | 2022-04-29 03:52:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int T,n,m,a[100010],b[100010];
char s[2000010];
void sol(){
scanf("%d%d%s",&n,&m,s);
for(int i=1;i<=max(n,m)+1;i++) a[i]=b[i]=0;
int l=n,r=m;
for(int i=0;i<n+m;i++){
if(s[i]=='1'){
if(l>r) a[l--]=1;
else b[r--]=1;
}
else{
if((l<=r&&l)||(!r)) a[l--]=0;
else b[r--]=0;
}
}
// for(int i=1;i<=n;i++) cout<<a[i];puts("");
// for(int i=1;i<=m;i++) cout<<b[i];puts("");
n=max(n,m);
for(int i=1;i<=n;i++) a[i]=a[i]+b[i];
for(int i=1;i<=n;i++) a[i+1]+=a[i]/2,a[i]&=1;
if(a[n+1]) n++;
while(!a[n]&&n>1) n--;
for(int i=n;i>=1;i--) printf("%d",a[i]);puts("");
}
int main(){
scanf("%d",&T);
while(T--) sol();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 5812kb
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: 69ms
memory: 6248kb
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:
10010000000 11100 10011100 110100101 100001110 1111111110 1000010111 111101101 1110100000 111101010 11110000 1000001101 1001011110 10101110 101110101 11100 1111010 1000010 1010001011 10001000101 10000101 1001000 111111110 1110 111 1111110001 10110111 1011010101 1111000 111000011 110 11111 11001010 1...
result:
wrong answer 1st lines differ - expected: '10011010100', found: '10010000000'