QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#380549#8057. Best Carry Player 4pope#WA 75ms3684kbC++142.3kb2024-04-07 05:43:422024-04-07 05:43:42

Judging History

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

  • [2024-04-07 05:43:42]
  • 评测
  • 测评结果:WA
  • 用时:75ms
  • 内存:3684kb
  • [2024-04-07 05:43:42]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); i++)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
#define int ll
typedef pair<int, int> pii;
typedef vector<int> vi;

#define trav(a, x) for (auto& a: x)
#define f first
#define s second
#define pb push_back
const char nl = '\n';

#ifdef DBG
void dbg_out() { cerr << nl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
    cerr << ' ' << H;
    dbg_out(T...);
}
#define dbg(...) dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int t; cin >> t;
    while (t--) {
        int m; cin >> m;
        int a[m], b[m];
        rep(i, 0, m) cin >> a[i];
        rep(i, 0, m) cin >> b[i];
        int sumA = 0, sumB = 0;
        rep(i, 0, m) {
            sumA += a[i];
            sumB += b[i];
        }
        if (sumA < sumB) a[0] += sumB-sumA;
        else b[0] += sumA-sumB;
        // try all m options for which one adds to 10+
        // with 2 ptr
        // now we want the k-1 sums to >= m-1
        int leftover = 0;
        int ans = 0;
        bool ok = 0;
        vector<int> remA(m);
        vector<int> remB(m);
        for(int i = 0; i<m; i++){
            remA[i] = a[i];
            remB[i] = b[i];
        }
        rep(i, 0, m) {
            int cur = min(a[i], leftover+b[m-1-i]);
            // take from leftover first
            if (leftover > 0 && a[i] > 0) {
                ok = 1;
            }
            ans += cur;
            remA[i] -= cur;
            remB[m-1-i] -= cur;
            leftover = leftover+b[m-1-i]-cur;
        }
        int bigA = 0;
        int bigB = 0;
        for(int i = 0; i<m; i++){
            if(a[i]>0){
                bigA = i;
            }
            if(b[i]>0){
                bigB = i;
            }
        }
        for(int i = 0; i<m; i++){
            if(remA[i]>0 && i+bigB>=m){
                ok = 1;
            }
            if(remB[i]>0 && i+bigA>=m){
                ok = 1;
            }
        }
        if(!ok){
            ans--;
        }
        cout << ans << endl;
    }
}


詳細信息

Test #1:

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

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: 75ms
memory: 3624kb

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

result:

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