QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682485#8057. Best Carry Player 4AKALemonWA 45ms3808kbC++232.5kb2024-10-27 15:40:022024-10-27 15:40:04

Judging History

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

  • [2024-10-27 15:40:04]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:3808kb
  • [2024-10-27 15:40:02]
  • 提交

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 (sa < sb) a[0] += sb - sa;
        else b[0] += sa - sb;
        i64 ans = 0;
        bool ok = true;
        int l = 0, r = n - 1;
        if (mxa + mxb < n) {
            std::cout << 0 << "\n";
            continue;
        }
        // for (int i = 0; i < n; i++) {
        //     if (a[i] && b[n - i - 1]) {
        //         int d = std::min<i64>(a[i], b[n - i - 1]);
        //         a[i] -= d;
        //         b[n - i - 1] -= d;
        //         ans += d;
        //     }
        // }
        // if (ans == 0) {
        //     std::cout << 0 << "\n";
        //     continue;
        // }
        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 = 0; i < n; i++) std::cerr << a[i] << " \n"[i == n - 1];
        // i64 last = 0;
        // while (l < n) {
        //     while (l < n && !a[l]) l++;
        //     if (l == n) break;
        //     if (last) ok = false;
        //     while (r >= 0 && (l + r + 1) > n) {
        //         last += b[r--];
        //     }
        //     int d = std::min<i64>(a[l], last);
        //     a[l] -= d, last -= d;
        //     ans += d;
        //     // std::cerr << l << ' ' << r << ' ' << d << "\n";
        //     if (last == 0) l++;
        // }
        // std::cerr << ok << ' ';
        // ans += a[n - 1] + b[n - 1];
        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: 3616kb

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: 45ms
memory: 3808kb

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
1
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
1
0
4
3
3
0
2
2
0
1
3
1
1
0
0
0
1
0
3
2
2
0
1
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 47th numbers differ - expected: '2', found: '1'