QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#831136 | #1289. A + B Problem | ZnPdCo | WA | 2ms | 12092kb | C++14 | 1.5kb | 2024-12-25 11:07:24 | 2024-12-25 11:07:53 |
Judging History
answer
#include <bits/stdc++.h>
#define N 2000010
using namespace std;
int T, n, m, ca, cb, cd;
int a[N], b[N], c[N], d[N];
char s[N];
void run(int n, int m) {
for(int i = 1; i <= n + m + 10; i++) a[i] = b[i] = c[i] = 0;
ca = 0, cb = 0;
for(int i = 1; i <= n + m; i++) {
if(ca == n) b[++cb] = s[i] - '0';
else if(cb == m) a[++ca] = s[i] - '0';
else if(s[i] == '0') b[++cb] = s[i] - '0';
else if(s[i] == '1') a[++ca] = s[i] - '0';
}
reverse(a + 1, a + ca + 1);
reverse(b + 1, b + cb + 1);
int cc = max(ca, cb);
for(int i = 1; i <= cc; i++) {
c[i] = a[i] + b[i];
if(c[i] >= 2) {
c[i + 1] += c[i] / 2;
if(i + 1 > cc) cc = i + 1;
c[i] %= 2;
}
}
while(c[cc] == 0 && cc > 1) cc--;
reverse(c + 1, c + cc + 1);
if(cc > cd) {
cd = cc;
for(int i = 1; i <= cd; i++) d[i] = c[i];
} else if(cc == cd) {
for(int i = 1; i <= cd; i++) {
if(c[i] < d[i]) break;
if(c[i] > d[i]) {
for(int j = 1; j <= cd; j++) d[j] = c[j];
break;
}
}
}
}
void solve() {
for(int i = 1; i <= n + m + 10; i++) d[i] = 0;
cd = 1;
scanf("%d%d%s", &n, &m, s + 1);
run(n, m);
run(m, n);
for(int i = 1; i <= cd; i++) printf("%d", d[i]);
printf("\n");
}
int main() {
// freopen("example2.in", "r", stdin);
// freopen("partition.out", "w", stdout);
scanf("%d", &T);
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 12092kb
input:
3 4 3 1000101 2 2 1111 1 1 00
output:
1101 0 0
result:
wrong answer 2nd lines differ - expected: '110', found: '0'