QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#569572#8057. Best Carry Player 4stavageWA 81ms8072kbC++171.9kb2024-09-17 00:51:152024-09-17 00:51:16

Judging History

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

  • [2024-09-17 00:51:16]
  • 评测
  • 测评结果:WA
  • 用时:81ms
  • 内存:8072kb
  • [2024-09-17 00:51:15]
  • 提交

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 double PI = acosl(-1.0);
const double eps = 1e-8;
const int MOD = 1e9 + 7;

int a[N], b[N], bei[N];
int m;
void solve()
{
    int ans = 0;
    scanf("%d", &m);
    int suma = 0, sumb = 0;
    int ma = 0, mb = 0;
    for (int i = 0; i < m; i++) {
        scanf("%d", &a[i]);
        suma += a[i];
        if (a[i]) ma = max(ma, i);
    }
    for (int i = 0; i < m; i++) {
        scanf("%d", &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;
        }
        mid = suma;
        suma = sumb;
        sumb = mid;
    }
    for (int i = 0; i < m; i++) bei[i] = a[i];
    b[0] += (suma - sumb);
    int f = 0;
    int t = m - 1;
    int r = m - 1;
    for (int i = 0; i < m; i++) {
        while (a[i] >= b[r] && i + r >= t && r >= 0) {
            if (i + r > t) f = 1;
            ans += b[r];
            a[i] -= b[r];
            r--;
        }
        if (r >= 0 && a[i] < b[r] && i + r >= t) {
            if (i + r > t && a[i]) f = 1;
            ans += a[i];
            b[r] -= a[i];
            a[i] = 0;
        }
    }
    int x = -1;
    for (int i = 0; i < m; i++) {
        if (bei[i] > a[i] && x == -1) x = i;
        if (x != -1 && a[i] > 0 && i > x) f = 1;
    }
//    cout<<ans<<endl<<endl;
    if (!f && ma + mb >= m) ans--;
    else if (!f) ans = 0;
    printf("%lld\n", ans);
}

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

詳細信息

Test #1:

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

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: 0
Accepted
time: 64ms
memory: 8072kb

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

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 38ms
memory: 8024kb

input:

1000
500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

0
1
1
2
2
2
0
0
0
3
1
1
2
0
1
0
1
1
3
0
0
4
3
1
4
4
0
0
2
1
3
3
0
0
1
0
1
1
0
0
2
1
2
0
3
1
3
1
3
4
2
1
1
2
3
0
0
1
2
0
0
1
1
1
1
2
1
2
2
0
2
2
1
1
3
0
0
1
2
0
1
3
0
0
1
1
0
0
1
0
3
1
2
0
0
5
1
1
1
3
1
4
1
0
0
0
0
0
1
3
1
2
1
0
0
0
0
0
1
1
0
4
0
1
1
3
0
1
0
0
2
3
0
1
2
1
1
1
0
3
0
0
3
2
1
1
0
1
0
1
...

result:

ok 1000 numbers

Test #4:

score: -100
Wrong Answer
time: 81ms
memory: 7944kb

input:

100000
5
119777838 337555280 806504015 458289944 321614229
979242871 431783189 423329635 193632121 7339369
5
189264782 667669243 753322761 861814678 224007583
977519325 104432095 940220826 712094722 903574615
5
977791540 278658984 601762324 633391706 36807634
689562032 997406456 118939957 891425821 ...

output:

1377698543
2884329841
1699584169
1780759937
2531472710
2754014935
1950741996
2577893498
1671531479
1655223784
1476887044
2115933812
1332546839
958870781
600795101
927483202
2136597299
1883468626
2291627593
1436067851
2412405837
1884010446
1960543235
2014856631
848686688
1069641213
2133866856
1597069...

result:

wrong answer 4th numbers differ - expected: '2132012702', found: '1780759937'