QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#343366#8057. Best Carry Player 4ucup-team045#WA 45ms3628kbC++202.0kb2024-03-02 14:36:422024-03-02 14:36:42

Judging History

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

  • [2024-03-02 14:36:42]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:3628kb
  • [2024-03-02 14:36:42]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
using LL = long long;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        vector<int> a(n), b(n);
        int mx1 = 0, mx2 = 0;
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if (a[i]) mx1 = i;
        }
        for(int i = 0; i < n; i++){
            cin >> b[i];
            if (b[i]) mx2 = i;
        }
        if (mx1 + mx2 < n){
            cout << 0 << '\n';
            continue;
        }
        a[0] = b[0] = 1e9;
        {
            auto c = a, d = b;
            LL ans = 0;
            int mn1 = n, mn2 = n;
            for(int i = 0; i < n; i++){
                int t = min(c[i], d[n - 1 - i]);
                if (t){
                    ans += t;
                    mn1 = min(mn1, i);
                    mn2 = min(mn2, n - 1 - i);
                    c[i] -= t;
                    d[n - 1 - i] -= t;
                }
            }
            bool flag = false;
            for(int i = mn1 + 1; i < n; i++){
                if (c[i]){
                    flag = true;
                }
            }
            for(int i = mn2 + 1; i < n; i++){
                if (d[i]){
                    flag = true;
                }
            }
            if (!flag){
                cout << ans - 1 << '\n';
                continue;
            }
        }
        // 可以完全匹配的情况.
        LL ans = 0;
        for(int i = 0, j = n - 1; i < n; i++){
            while(a[i] > 0){
                while(j >= 0 && b[j] == 0) j--;
                if (j < 0 || i + j < n - 1) break;
                int t = min(a[i], b[j]);
                ans += t;
                a[i] -= t; b[j] -= t;
            }
        }
        cout << ans << '\n';
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

result:

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