QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#386990#8057. Best Carry Player 4shiwtWA 1ms7708kbC++142.6kb2024-04-11 22:29:382024-04-11 22:29:39

Judging History

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

  • [2024-04-11 22:29:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7708kb
  • [2024-04-11 22:29:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

long long a[500010], b[500010];
bool matcheda[500010], matchedb[500010];
long long suma, sumb;

int main() {
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        long long ansa = 0, ansb = 0;
        suma = sumb = 0;
        for (int i = 0; i < n; i++) {
            matcheda[i] = matchedb[i] = 0;
            cin >> a[i];
            suma += a[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> b[i];
            sumb += b[i];
        }
        if(suma > sumb) {
            b[0] += suma - sumb;
        } else {
            a[0] += sumb - suma;
        }
        bool flag = false;
        for (int i = n - 1; i >= (n - 1) / 2; i--) {
            int match = n - 1 - i;
            while(match <= i) {
                // cout << "match " << i << " " << match << endl;
                if(match + i >= n && b[match])
                    flag = true;
                if(a[i] <= b[match]) {
                    if(a[i]!=b[match] && match == n - 1 - i && ansa > 0) {
                        cout << "check" << endl;
                        flag = true;
                    }
                    ansa += a[i];
                    b[match] -= a[i];
                    a[i] = 0;
                    break;
                } else {
                    ansa += b[match];
                    a[i] -= b[match];
                    b[match] = 0;
                    match++;
                }
            }
            match = n - 1 - i;
            while(match <= i) {
                // cout << "match2 " << i << " " << match << endl;
                if(match + i >= n && a[match])
                    flag = true;
                if(b[i] <= a[match]) {
                    if(b[i] != a[match] && match == n - 1 - i && ansb > 0) {
                        // cout << "check" << endl;
                        flag = true;
                    }
                    ansb += (long long)b[i];
                    a[match] -= b[i];
                    b[i] = 0;
                    break;
                } else {
                    
                    ansb += (long long)a[match];
                    b[i] -= a[match];
                    a[match] = 0;
                    match++;
                }
            }
            // cout << "check" << i << " " << ans << endl;
        }
        long long ans = ansa + ansb;
        if(!flag && ans)
            ans--;
        cout << ans << "\n";
    }

    //system("pause");
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7708kb

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
check
1
check
2
check
467900
check
check
29

result:

wrong output format Expected integer, but "check" found