QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#355049#8057. Best Carry Player 4foreverlasting#WA 48ms3796kbC++201.5kb2024-03-16 11:40:082024-03-16 11:40:09

Judging History

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

  • [2024-03-16 11:40:09]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:3796kb
  • [2024-03-16 11:40:08]
  • 提交

answer

#include <bits/stdc++.h>

using LL = long long;
using ld = long double;
using Pair = std::pair<int, ld>;
#define inf 1'000'000'000

void solve(const int &Case) {
    int m;
    std::cin >> m;
    std::vector<LL> a(m), b(m);
    int mx = 0;
    for (auto &x: a)std::cin >> x;
    for (auto &x: b)std::cin >> x;
    a[0] = (LL) m * 3'000'000'000;
    b[0] = (LL) m * 3'000'000'000;
    for (int i = 0; i < m; i++) {
        if (a[i] > 0)mx = i;
    }
    for (int i = m - 1; i >= 0; i--) {
        if (b[i] > 0) {
            if (i + mx < m) {
                std::cout << 0 << '\n';
                return;
            }
            else break;
        }
    }
    LL ans = 0;
    int fl = 1;
    int r = m - 1, l = 0;
    while (r >= 0 && l < m) {
        while (l + r < m - 1) {
            if (b[l] > 0 && mx + l >= m)fl = 0;
            l++;
        }
        if (a[r] > 0 && b[l] > 0 && l + r >= m)fl = 0;
        if (a[r] > b[l]) {
            a[r] -= b[l];
            ans += b[l], l++;
        }
        else if (a[r] < b[l]) {
            b[l] -= a[r];
            ans += a[r], r--;
        }
        else {
            ans += b[l], r--, l++;
        }
    }
    ans -= fl;
    std::cout << ans << '\n';
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int T = 1;
    std::cin >> T;
    for (int Case = 1; Case <= T; Case++)solve(Case);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3796kb

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'