QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#386985#8057. Best Carry Player 4shiwtWA 76ms5732kbC++142.9kb2024-04-11 22:25:042024-04-11 22:25:04

Judging History

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

  • [2024-04-11 22:25:04]
  • 评测
  • 测评结果:WA
  • 用时:76ms
  • 内存:5732kb
  • [2024-04-11 22:25:04]
  • 提交

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(b[i] > 0 && 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;
}

/*
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

*/
/*
02
1

0123
  03

5
2 0 0 0 1
1 0 0 0 3

3

 004
0444
 0034
23411
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5728kb

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: 76ms
memory: 5732kb

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

result:

wrong answer 12th numbers differ - expected: '1', found: '0'