QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#346783#8057. Best Carry Player 4berarchegas#WA 48ms9684kbC++204.1kb2024-03-08 23:22:192024-03-08 23:22:20

Judging History

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

  • [2024-03-08 23:22:20]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:9684kb
  • [2024-03-08 23:22:19]
  • 提交

answer

#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
 
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
    
const int MOD = 1e9 + 7;
const int MAXN = 5e5 + 5;
const ll INF = 2e18;

ll resp = 0;

ll a[MAXN], b[MAXN], va[MAXN], vb[MAXN];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        resp = 0;
        int m;
        cin >> m;
        ll tota = 0, totb = 0;
        for(int i = 0; i < m; i++) {
            cin >> a[i];
            va[i] = a[i];
            tota += a[i];
        }
        for(int i = 0; i < m; i++) {
            cin >> b[i];
            vb[i] = b[i];
            totb += b[i];
        }
        //cout << tota << ' ' << totb << '\n';
        if(tota > totb) {
            b[0] += tota - totb;
            vb[0] = b[0];
        }
        else {
            a[0] += totb - tota;
            va[0] = a[0];
        }
        int pa = 0, pb = m - 2;
        while(resp == 0 && pa < m - 1 && pb >= 0) {
            if(pa + pb < m) {
                pa++;
            }
            if(a[pa] == 0) {
                pa++;
            }
            if(b[pb] == 0) {
                pb--;
            }
            if(a[pa] > 0 && b[pb] > 0 && (pa + pb) >= m) {
                a[pa]--; b[pb]--; resp++;
            }
        }
        if(resp == 0) {
            int pa = 0, pb = m - 1;
            while(resp == 0 && pa < m && pb >= 0) {
                if(pa + pb < m) {
                    pa++;
                }
                if(a[pa] == 0) {
                    pa++;
                }
                if(b[pb] == 0) {
                    pb--;
                }
                if(a[pa] > 0 && b[pb] > 0 && (pa + pb) >= m) {
                    a[pa]--; b[pb]--; resp++;
                }
            }
        }
        if(resp == 0) {
            cout << 0 << '\n';
            continue;
        }
        pa = 0, pb = m - 1;
        while(pa < m && pb >= 0) {
            if(pa + pb < m - 1) {
                pa++;
            }
            if(a[pa] == 0) {
                pa++;
            }
            if(b[pb] == 0) {
                pb--;
            }
            if(a[pa] > 0 && b[pb] > 0 && (pa + pb) >= m - 1) {
                ll mn = min(a[pa], b[pb]);
                resp += mn;
                a[pa] -= mn; b[pb] -= mn;
            }
        }
        ll r1 = resp;
        resp = 0;
        for(int i = 0; i < m; i++) {
            a[i] = va[i]; b[i] = vb[i];
        }
        pa = 0, pb = m - 2;
        while(resp == 0 && pa < m - 1 && pb >= 0) {
            if(pa + pb < m) {
                pa++;
            }
            if(b[pa] == 0) {
                pa++;
            }
            if(a[pb] == 0) {
                pb--;
            }
            if(b[pa] > 0 && a[pb] > 0 && (pa + pb) >= m) {
                b[pa]--; a[pb]--; resp++;
            }
        }
        if(resp == 0) {
            int pa = 0, pb = m - 1;
            while(resp == 0 && pa < m && pb >= 0) {
                if(pa + pb < m) {
                    pa++;
                }
                if(b[pa] == 0) {
                    pa++;
                }
                if(a[pb] == 0) {
                    pb--;
                }
                if(b[pa] > 0 && a[pb] > 0 && (pa + pb) >= m) {
                    b[pa]--; a[pb]--; resp++;
                }
            }
        }
        if(resp == 0) {
            cout << 0 << '\n';
            continue;
        }
        pa = 0, pb = m - 1;
        while(pa < m && pb >= 0) {
            if(pa + pb < m - 1) {
                pa++;
            }
            if(a[pa] == 0) {
                pa++;
            }
            if(b[pb] == 0) {
                pb--;
            }
            if(a[pa] > 0 && b[pb] > 0 && (pa + pb) >= m - 1) {
                ll mn = min(a[pa], b[pb]);
                resp += mn;
                a[pa] -= mn; b[pb] -= mn;
            }
        }
        cout << max(r1, resp) << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9672kb

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: 48ms
memory: 9684kb

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

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