QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#450439 | #1289. A + B Problem | MrPython | AC ✓ | 59ms | 4080kb | C++14 | 1.8kb | 2024-06-22 13:27:29 | 2024-06-22 13:27:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
using uli = unsigned long long int;
istream &fin = cin;
ostream &fout = cout;
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t T;
fin >> T;
while (T--) {
size_t n, m;
fin >> n >> m;
if (n < m)
swap(n, m);
vector<bool> a(n + m);
for (vector<bool>::reference i : a) {
char c;
fin >> c;
i = c == '1';
}
vector<bool> type(m + n);
fill(type.begin() + m, type.end(), true);
vector<size_t> x_zero_pos;
for (size_t i = m + n - 1; i < m + n && i >= m; --i)
if (!a[i])
x_zero_pos.emplace_back(i);
for (size_t i = m - 1; i < m && !x_zero_pos.empty(); --i)
if (a[i]) {
size_t e = x_zero_pos.back();
if (n + m - 1 - e < m - 1 - i)
break;
x_zero_pos.pop_back();
type[i] = true, type[e] = false;
}
vector<bool> x, y;
for (size_t i = m + n - 1; i < m + n; --i)
(type[i] ? x : y).emplace_back(a[i]);
vector<bool> ans;
bool nx = false;
for (size_t i = 0; i < m; ++i) {
ans.emplace_back((x[i] + y[i] + nx) & 1);
nx = (x[i] + y[i] + nx) >= 2;
}
for (size_t i = m; i < n; ++i) {
ans.emplace_back(x[i] ^ nx);
nx = x[i] & nx;
}
ans.emplace_back(nx);
while (ans.size() > 1 && !ans.back())
ans.pop_back();
for_each(ans.rbegin(), ans.rend(), [](bool b) { fout.put(b + '0'); });
fout.put('\n');
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
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: 59ms
memory: 4080kb
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