QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#467436#1289. A + B ProblemDecember456WA 22ms7740kbC++141.4kb2024-07-08 16:12:352024-07-08 16:12:35

Judging History

你现在查看的是最新测评结果

  • [2024-07-08 16:12:35]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:7740kb
  • [2024-07-08 16:12:35]
  • 提交

answer

#include <algorithm>
#include <cstdio>

constexpr int MAXN = 1000000 + 2;

int pos[MAXN << 1];

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;
        }
        for (int i = 1; i <= n + m; i ++) {
            pos[i] = MAXN << 1;
        }
        for (int i = 0, cnt = 0; i < n + m; i ++) {
            if (a[i] == '1') {
                pos[++ cnt] = i;
            }
        }

        for (int i = 0, p1 = n, p2 = m, cnt = 0; i < n + m; i ++) {
            if (a[i] == '0') {
                (p2 ? p2 : p1) --;
            } else {
                cnt ++;

                if (pos[cnt + p1 - p2] - i - p1 >= 0) {
                    b[-- p1] = true;
                } else {
                    c[-- p2] = true;
                }
            }
        }

        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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5612kb

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: 22ms
memory: 7740kb

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:

wrong answer 10993rd lines differ - expected: '111111111111111111111111111111...1111111111111111111111111111110', found: '111111111111111111111111111111...1111111111111111111111111111111'