QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682492#8057. Best Carry Player 4AKALemonWA 48ms3824kbC++231.5kb2024-10-27 15:42:102024-10-27 15:42:11

Judging History

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

  • [2024-10-27 15:42:11]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:3824kb
  • [2024-10-27 15:42:10]
  • 提交

answer

#include<bits/stdc++.h>
using i64 = long long;

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    
    int t;
    std::cin >> t;
    while (t--) {
        int n; std::cin >> n;
        std::vector<i64> a(n), b(n);
        i64 sa = 0, sb = 0;
        int mxa = 0, mxb = 0;
        for (int i = 0; i < n; i++) std::cin >> a[i], sa += a[i];
        for (int i = 0; i < n; i++) std::cin >> b[i], sb += b[i];
        for (int i = 0; i < n; i++) {
            if (a[i]) mxa = i;
            if (b[i]) mxb = i;
        }
        if (mxa + mxb < n) {
            std::cout << 0 << "\n";
            continue;
        }

        if (sa < sb) a[0] += sb - sa;
        else b[0] += sa - sb;

        i64 ans = 0;
        bool ok = true;
        int l = 0, r = n - 1;

        while (l < n) {
            while (l < n && !a[l]) l++;
            while (r >= 0 && !b[r]) r--;
            if (l == n || r == -1) break;
            if (l + r + 1 < n) {
                l++;
                continue;
            } else if (l + r + 1 >= n) {
                int d = std::min(a[l], b[r]);
                a[l] -= d, b[r] -= d;
                ans += d;
                if (l + r + 1 > n) ok = false;
            }
        }

        for (int i = 1; i < n; i++) {
            if (a[i] && i <= mxa) ok = false;
            if (b[i] && i <= mxb) ok = false;
        }
        std::cout << ans - ok << "\n";
        
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 48ms
memory: 3628kb

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
3
3
3
2
0
0
1
1
3
0
3
0
0
0
0
0
0
0
4
0
4
1
0
2
3
3
1
5
0
0
2
0
0
1
1
0
0
3
5
3
2
2
2
0
1
2
3
2
0
3
0
2
1
1
0
1
0
4
0
0
2
2
0
3
3
0
2
0
1
0
0
2
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
2
0
0
2
4
1
3
3
2
2
2
0
2
0
0
2
3
1
3
1
0
3
2
3
0
1
2
0
1
1
...

result:

wrong answer 51st numbers differ - expected: '2', found: '3'