QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#467783 | #1289. A + B Problem | December456 | AC ✓ | 11ms | 7760kb | C++14 | 1.5kb | 2024-07-08 17:27:00 | 2024-07-08 17:27:00 |
Judging History
answer
#include <algorithm>
#include <cstdio>
constexpr int MAXN = 1000000 + 2;
int lst[MAXN];
char a[MAXN << 1], b[MAXN], c[MAXN], ans[MAXN];
int main() {
int T;
scanf("%d", &T);
while (T --) {
int n, m;
scanf("%d%d%s", &n, &m, a);
if (n < m) {
std::swap(n, m);
}
for (int i = 0; i <= n; i ++) {
b[i] = c[i] = false;
}
int maxi = m, lst1 = -1;
for (int i = 0; i < m; i ++) {
if (a[i] == '1') {
lst[i] = lst1;
lst1 = i;
}
}
for (; maxi < n + m && lst1 >= 0; maxi ++) {
if (a[maxi] == '1') {
continue;
}
if (n + lst1 >= maxi) {
lst1 = lst[lst1];
} else {
break;
}
}
int pt = n;
for (int i = 0; i < maxi - m; i ++) {
b[-- pt] = true;
}
for (int i = maxi; i < n + m; i ++) {
b[-- pt] = a[i] - '0';
}
for (int i = 0; i <= lst1; i ++) {
c[m - i - 1] = a[i] - '0';
}
for (int i = 0, carry = 0; i <= n; i ++) {
ans[i] = b[i] ^ c[i] ^ carry;
carry = b[i] + c[i] + carry > 1;
}
int p = n;
while (p && !ans[p]) {
p --;
}
for (int i = p; i >= 0; i --) {
putchar(ans[i] ^ '0');
}
putchar('\n');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7644kb
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: 11ms
memory: 7760kb
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