QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#341570#8057. Best Carry Player 4Vengeful_Spirit#WA 46ms7840kbC++142.0kb2024-02-29 19:50:412024-02-29 19:50:41

Judging History

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

  • [2024-02-29 19:50:41]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:7840kb
  • [2024-02-29 19:50:41]
  • 提交

answer

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

const int MN = 5e5+5;
int a[MN], b[MN], r[MN];
bool ua[MN], ub[MN];
int getr(int i) {
    if(r[i] == i) return i;
    return r[i] = getr(r[i]);
}

void solve() {
    int m;
    cin >> m;
    long long _1 = 0, _2 = 0;
    for(int i = 0; i < m; ++i) cin >> a[i], ua[i] = 0, _1 += a[i];
    for(int i = 0; i < m; ++i) cin >> b[i], ub[i] = 0, _2 += b[i];
    // cal num9
    long long num9 = 0, num10 = 0;
    if(_1 < _2) a[0] += _2 - _1;
    if(_2 < _1) a[0] += _1 - _2;

    for(int i = 0; i < m; ++i) {
        int cc = min(a[i], b[m-1-i]);
        num9 += cc;
        a[i] -= cc;
        b[m-1-i] -= cc;
        if(cc) ua[i] = ub[m-1-i] = 1;
    }

    for(int i = 0; i < m; ++i) r[i] = i;
    for(int i = m-1; i; --i) {
        int j = m-i; j = getr(j);
        while(j < m) {
            // cout << i << " " << j << " " << num10 << "\n";
            int cc = min(a[i], b[j]);
            num10 += cc;
            a[i] -= cc;
            b[j] -= cc;
            if(b[j] > 0) break;
            if(j == m-1) break;
            r[j] = getr(j+1);
            j = r[j];
        }
    }

    // cout << num9 << " " << num10 << " ";
    if(num10 == 0) {
        bool fl = 0, aa = 0, bb = 0;
        for(int i = 0; i < m; ++i) {
            if(aa && a[i]) {fl = 1; break;}
            if(bb && b[i]) {fl = 1; break;}
            aa |= ua[i];
            bb |= ub[i];
        }
        if(fl) cout << num9 << "\n";
        else cout << max(0ll, num9 - 1) << "\n";
    } else {
        cout << num9 + num10 << "\n";
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("in.txt", "r", stdin);
    int T;
    cin >> T;
    while(T--) solve();

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

/*
5
1
2
467900
29
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 46ms
memory: 7768kb

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:

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

result:

wrong answer 1st numbers differ - expected: '2', found: '1'