QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#468157 | #1289. A + B Problem | yyyyxh | AC ✓ | 7ms | 5508kb | C++14 | 1.1kb | 2024-07-08 19:34:54 | 2024-07-08 19:34:55 |
Judging History
answer
#include <cstdio>
#include <algorithm>
using namespace std;
int read(){
char c=getchar();int x=0;
while(c<48||c>57) c=getchar();
do x=x*10+(c^48),c=getchar();
while(c>=48&&c<=57);
return x;
}
const int N=2000003;
int n,m,rk;
bool s[N],t[N],res[N];
void solve(){
n=read();m=read();rk=0;
char cc=getchar();
while(cc!=48&&cc!=49) cc=getchar();
for(int i=1;i<=n+m;++i) s[i]=cc^48,cc=getchar();
if(n<m) swap(n,m);
int ps=m,lim=n+m;
for(int i=m+1;i<=n+m;++i)
if(!s[i]){
while(ps&&!s[ps]) --ps;
if(!ps||n+ps<i){lim=i-1;break;}
s[ps]=0;
}
for(int i=1;i<=lim-m;++i) t[++rk]=1;
for(int i=lim+1;i<=n+m;++i) t[++rk]=s[i];
reverse(s+1,s+m+1);
reverse(t+1,t+n+1);
for(int i=m+1;i<=n+m+1;++i) s[i]=0;
for(int i=n+1;i<=n+m+1;++i) t[i]=0;
int len=0;
for(int i=1,carry=0;i<=n||i<=m||carry;++i){
len=i;
carry+=s[i]+t[i];
res[i]=carry&1;
carry>>=1;
}
while(len&&!res[len]) --len;
if(len){
for(int i=len;i;--i) putchar(res[i]^48);
putchar('\n');
}
else puts("0");
}
int main(){
int tc=read();
while(tc--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5376kb
input:
3 4 3 1000101 2 2 1111 1 1 00
output:
1101 110 0
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 7ms
memory: 5508kb
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:
10011010100 11100 10101000 110100101 100001110 10000001100 1000010111 111101101 1110100000 111101010 11110000 1000011101 1001011110 10101110 101110101 11100 1111010 1000010 1011100010 10010101001 10010001 1001010 1000000010 1110 111 1111110001 10110111 1100010101 10000000 111000011 110 11111 1100101...
result:
ok 11110 lines