QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#461874#8057. Best Carry Player 4ucup-team3678#WA 58ms3884kbC++141.5kb2024-07-03 08:59:002024-07-03 08:59:00

Judging History

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

  • [2024-07-03 08:59:00]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:3884kb
  • [2024-07-03 08:59:00]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 5;

long long a[N], b[N], ta[N], tb[N];

signed main() {
    int T; scanf("%d", &T);
    while (T--) {
        int n; scanf("%d", &n);
        for (int i = 0; i < n; ++i) scanf("%lld", &a[i]), ta[i] = a[i];
        for (int i = 0; i < n; ++i) scanf("%lld", &b[i]), tb[i] = b[i];
        a[0] = 1e18, b[0] = 1e18;
        long long res = 0;
        int flg = 0;
        int mxa = 0, mxb = 0;
        for (int i = 0, j = n - 1; i < n; ) {
            while (i < n && !a[i]) ++i;
            while (~j && !b[j]) --j;
            if (i == n || !~j) break;
            if (i + j >= n - 1) {
                if (i + j >= n) flg = 1;
                long long v = min(a[i], b[j]);
                mxa = max(mxa, i), mxb = max(mxb, j);
                a[i] -= v, b[j] -= v, res += v;
            } else ++i;
        }
        if (flg) printf("%lld\n", res);
        else {
            int flag = 0;
            for (int i = 0; i < n; ++i) {
                if (a[i] && i + mxb >= n) flag = 1;
                if (b[i] && i + mxa >= n) flag = 1;
            }
            if (flag) {
                printf("%lld\n", res);
                continue;
            }
            int mx1 = 0, mx2 = 0;
            for (int i = n - 1; ~i; --i) if (ta[i]) {mx1 = i; break;}
            for (int i = n - 1; ~i; --i) if (tb[i]) {mx2 = i; break;}
            if (mx1 + mx2 >= n) printf("%lld\n", res - 1);
            else puts("0");
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3884kb

input:

5
2
1 2
3 4
3
1 0 1
0 1 0
4
1 0 0 1
1 1 1 1
5
123456 114514 1919810 233333 234567
20050815 998244353 0 0 0
10
5 3 5 3 2 4 2 4 1 5
9 9 8 2 4 4 3 5 3 0

output:

5
1
2
467900
29

result:

ok 5 number(s): "5 1 2 467900 29"

Test #2:

score: -100
Wrong Answer
time: 58ms
memory: 3884kb

input:

100000
5
0 1 1 1 1
0 0 1 0 0
5
0 0 0 0 0
1 1 1 0 0
5
0 0 2 1 1
0 2 1 0 1
5
0 0 0 0 0
1 2 1 0 0
5
0 1 0 1 1
0 0 1 1 1
5
2 0 0 0 1
1 0 0 0 3
5
2 0 0 1 1
0 2 1 1 1
5
0 0 0 0 2
0 0 0 0 1
5
0 0 0 0 0
0 1 1 0 0
5
4 0 0 0 0
0 0 0 1 0
5
0 0 0 0 1
2 1 1 0 0
5
0 2 3 0 0
0 0 0 1 0
5
1 1 1 0 1
1 0 1 0 1
5
0 0 0...

output:

2
0
4
0
4
3
3
2
0
0
1
1
3
0
3
0
0
0
0
0
0
0
4
0
4
1
0
2
4
3
1
5
0
0
2
0
0
1
1
0
0
3
5
3
2
2
2
0
1
2
2
2
0
4
0
2
1
1
0
1
0
4
0
0
2
2
0
3
3
0
2
0
1
0
0
1
1
2
0
3
4
0
2
5
0
2
1
0
0
0
3
2
3
0
2
0
4
3
3
0
2
2
0
1
3
1
1
0
0
0
1
0
3
2
2
0
2
1
1
0
1
0
0
2
4
1
3
3
2
2
2
0
2
0
0
2
3
1
3
1
0
2
2
3
0
1
2
0
1
1
...

result:

wrong answer 5th numbers differ - expected: '3', found: '4'