QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#569327#8057. Best Carry Player 4stavageWA 45ms5796kbC++172.4kb2024-09-16 22:06:212024-09-16 22:06:21

Judging History

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

  • [2024-09-16 22:06:21]
  • 评测
  • 测评结果:WA
  • 用时:45ms
  • 内存:5796kb
  • [2024-09-16 22:06:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
#define int LL
#define double LD
#define endl "\n"
typedef pair<int, int> PII;
const int N = 5e5 + 5;
const int INF = 0x3f3f3f3f;
const int inf = 0x3f3f3f3f3f3f3f3f;
const double PI = acosl(-1.0);
const double eps = 1e-8;
const int MOD = 1e9 + 7;

int a[N], b[N];
int m;
void solve()
{
    cin >> m;
    int suma = 0, sumb = 0;
    int ma = 0, mb = 0;
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        suma += a[i];
        if (a[i]) ma = max(ma, i);
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
        sumb += b[i];
        if (b[i]) mb = max(mb, i);
    }
    if (sumb > suma) {
        int mid;
        for (int i = 0; i < m; i++) {
            mid = a[i];
            a[i] = b[i];
            b[i] = mid;
        }
    }
    else if (suma == sumb) {
        int f = 0;
        for (int i = 0; i < m; i++) {
            if (a[i] > b[i]) {
                f = 1;
                break;
            }
        }
        if (f) {
            int mid;
            for (int i = 0; i < m; i++) {
                mid = a[i];
                a[i] = b[i];
                b[i] = mid;
            }
        }
    }
    int ans = 0;
    int ca = -1, cb = -1;
    for (int i = 0; i < m; i++) {
        if (a[i] && b[m - i]) {
            ca = i;
            cb = m - i;
            break;
        }
    }
    if (ca == -1 && cb == -1) {
        if (ma + mb >= m) {
            ca = ma;
            cb = mb;
        }
    }
    if (ca != -1 && cb != -1) {
//        cout << ca << " " << cb << " " << endl;
        a[ca]--;
        b[cb]--;
        ans++;
    }
    else {
        cout << 0 << endl;
        return;
    }
    int r = m - 1;
    int t = m - 1;
    for (int i = 0; i < m; i++) {
        while (r >= 0 && a[i] >= b[r] && i + r >= t) {
            ans += b[r];
            a[i] -= b[r];
            r--;
        }
        if (r >= 0 && a[i] < b[r] && i + r >= t) {
            ans += a[i];
            b[r] -= a[i];
            a[i] = 0;
        }
    }
    ans += a[m - 1];
//    cout << "olahfc\n";
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    int _;
    cin >> _;
//    _ = 1;
    while (_--) {
        solve();
    }
    return 0;
}

详细

Test #1:

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

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

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

result:

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