QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#767604#8057. Best Carry Player 4yangjlWA 41ms3524kbC++201.7kb2024-11-20 21:24:512024-11-20 21:24:55

Judging History

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

  • [2024-11-20 21:24:55]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:3524kb
  • [2024-11-20 21:24:51]
  • 提交

answer

/**
 *    author:  yangjl
 *    created: 2024.11.20 20:45:08
**/
#include <bits/stdc++.h>
#ifdef YJL
#include "debug.h"
#else
#define debug(...)0
#endif
using namespace std;
using ll = long long;

template<class T>
istream& operator>>(istream& is, vector<T>& v) {
    for(auto& x : v) {
        is >> x;
    }
    return is;
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int tt;
    cin >> tt;
    while(tt--) {
        int m;
        cin >> m;
        vector<int> a(m), b(m);
        cin >> a >> b;
        ll suma = accumulate(a.begin(), a.end(), 0ll);
        ll sumb = accumulate(b.begin(), b.end(), 0ll);
        if(suma < sumb) {
            swap(suma, sumb);
            swap(a, b);
        }

        bool carryExist = false;
        for(int i = 1, j = m - 1; i < m; ++i) {
            while(j > 1 and b[j] == 0) {
                j--;
            }
            if(a[i] > 0 and i + j >= m and b[j] > 0) {
                a[i] --;
                b[j]--;
                carryExist = true;
                break;
            }
        }
        if(!carryExist) {
            cout << "0\n";
            continue;
        }

        ll tmp = min<ll>(suma - sumb, a.back());
        a.back() -= tmp;
        int ans = tmp + 1;
        for(int i = m - 1, j = 0; i >= 0; --i) {
            int x = a[i];
            while(j < m and i + j < m - 1) {
                j++;
            }
            while(x and j < m) {
                int t = min(x, b[j]);
                ans += t;
                x -= t;
                b[j] -= t;
                if(b[j] == 0) {
                    j++;
                }
            }
        }
        cout << ans << '\n';
    }
    return 0;
}
/*


*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 41ms
memory: 3496kb

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

result:

wrong answer 23rd numbers differ - expected: '4', found: '3'