QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#333746#8057. Best Carry Player 4ucup-team3160#WA 15ms3876kbC++172.2kb2024-02-20 14:44:222024-02-20 14:44:23

Judging History

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

  • [2024-02-20 14:44:23]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3876kb
  • [2024-02-20 14:44:22]
  • 提交

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 = 1e2 + 10;
ll a[N], b[N];
pair<ll, ll> _f[N][2];
auto f = _f + 1;

int main() {
    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;
        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)});
            
            if(p.second > 0) 
                f[i][1] = max(f[i][1], {p.first + t1, min(b[j], b[j] + p.second - t1)});
            else if(p.first > 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;
        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] = {};
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 15ms
memory: 3876kb

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:

0 
0 
3 
0 
2 
3 
3 
0 
-1 
0 
1 
0 
3 
-1 
2 
-1 
0 
0 
0 
0 
0 
-1 
2 
1 
3 
1 
0 
1 
2 
1 
1 
2 
0 
-1 
1 
0 
-1 
1 
1 
0 
0 
3 
3 
3 
0 
1 
1 
0 
1 
1 
0 
2 
-1 
0 
1 
2 
1 
1 
-1 
0 
0 
4 
1 
0 
1 
2 
0 
3 
1 
0 
1 
0 
0 
0 
0 
0 
1 
2 
1 
1 
4 
0 
1 
3 
0 
2 
1 
1 
0 
-1 
3 
0 
2 
-1 
2 
-1 
4...

result:

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