QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#333756#8057. Best Carry Player 4ucup-team3160#WA 8ms38752kbC++172.4kb2024-02-20 14:55:272024-02-20 14:55:27

Judging History

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

  • [2024-02-20 14:55:27]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:38752kb
  • [2024-02-20 14:55:27]
  • 提交

answer

#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include "lib.h"
#endif
#define rep(i, min, max) for(int i = (min); i <= (max); ++i)
#define nrep(i, max, min) for(int i = (max); i >= (min); --i)
#define reads(str) (scanf("%s", str + 1), strlen(str + 1))
#define case() int Ts = read(); rep(T, 1, Ts)
#define putf(flag) puts((flag) ? "YES" : "NO")
#define put(x) printf("%d ", x)
#define putl(x) printf("%lld ", x)
#define endl() putchar('\n')
using namespace std;

typedef long long ll;
inline int read()
{
    int now=0; bool nev=false; char c=getchar();
    while(c<'0' || c>'9') { if(c=='-') nev=true; c=getchar(); }
    while(c>='0' && c<='9') { now=(now<<1)+(now<<3)+(c&15); c=getchar(); }
    return nev?-now:now;
}

const int N = 1e6 + 10;
const ll INF = 1e16;
ll a[N], b[N];
pair<ll, ll> _f[N][2];
auto f = _f + 1;

int main() {
    rep(i, 0, N - 1) f[i][0] = f[i][1] = {-INF, -INF};
    case() {
        int n = read();
        ll sum = 0, s1 = 0, s2 = 0;
        rep(i, 0, n - 1) a[i] = read(), s1 += a[i];
        rep(i, 0, n - 1) b[i] = read(), s2 += b[i];
        ll a0 = a[0], b0 = b[0];
        if(s1 < s2) a[0] += s2 - s1;
        else b[0] += s1 - s2;
        f[-1][0] = {0, 0};
        f[-1][1] = {-INF, -INF};
        rep(i, 0, n - 1) {
            int j = n - 1 - i;
            auto p = f[i - 1][0], q = f[i - 1][1];
            ll t1 = min(a[i], b[j] + p.second);
            f[i][0] = max(f[i][0], {p.first + t1, min(b[j], b[j] + p.second - t1)});
            ll t2 = min(a[i], b[j] + q.second);
            f[i][1] = max(f[i][1], {q.first + t2, min(b[j], b[j] + q.second - t2)});
            // print(q.first + t2);
            
            if(p.second > 0 && a[i] > 0) 
                f[i][1] = max(f[i][1], {p.first + t1, min(b[j], b[j] + p.second - t1)});
            else if(p.first > 0 && a[i] > 0) {
                p.first --, p.second ++;
                ll t1 = min(a[i], b[j] + p.second);
                f[i][1] = max(f[i][1], {p.first + t1, min(b[j], b[j] + p.second - t1)});
                p.first ++, p.second --;
            }
            // print(f[i][0].first, f[i][0].second, f[i][1].first, f[i][1].second);
        }
        ll v = f[n - 1][1].first;
        if(v < 0) v = 0;
        // v = min(v, s1 + b0 - 1);
        // v = min(v, s2 + a0 - 1);
        putl(v); endl();
        rep(i, 0, n + 1) f[i][0] = f[i][1] = {-INF, -INF};
    }
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 38752kb

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: 8ms
memory: 38112kb

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

result:

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