QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376257#8057. Best Carry Player 4jxuWA 52ms3824kbC++172.4kb2024-04-04 00:36:572024-04-04 00:36:57

Judging History

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

  • [2024-04-04 00:36:57]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:3824kb
  • [2024-04-04 00:36:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<bool> vb;
typedef tuple<int,int,int> ti;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vi> vii;
typedef vector<vii> viii;

template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define FOR(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(x,A) for (auto& x : A)

#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ins insert

const int MOD = 1000000007;
const char nl = '\n';

int help(vi A, vi B) {
    int m = sz(A);

    int j = 0;
    int mismatch = 0;
    int match = 0;
    FORd(i, 0, m) {
        int a = A[i];
        // I am 9, I want to match with 0
        while(j < m && i + j + 1 < m) j++;

        while(a && j < m) {
            int b = B[j];
            int cap = min(a, b);


            // cout << cap << " matches " << i << " " << j << nl;
            
            match += cap;
            a -= cap;
            B[j] -= cap;
            if (i + j >= m && cap > 0) mismatch++;

            if (B[j] == 0) j++;
        }
    }
    // cout << nl;

    if (match == 0) return 0;

    if (mismatch == 0) match--;
    return match;
}

int solve(int tt) {
    int m; cin >> m;

    vi A(m), B(m);
    trav(x, A) cin >> x;
    trav(x, B) cin >> x;

    int x = accumulate(all(A), 0);
    int y = accumulate(all(B), 0);

    if (x < y) {
        A[0] += y - x;
    } else {
        B[0] += x - y;
    }

    int ans = max(help(A, B), help(B, A));
    cout << ans << nl;
    
    

    tt++;
    return 0;
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; i++) {
        if (solve(i)) break;
    }
    T++;
    return 0;
}

详细

Test #1:

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

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: 52ms
memory: 3824kb

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
1
1
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
1
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
1
1
1
...

result:

wrong answer 63rd numbers differ - expected: '0', found: '1'