QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#678545#8057. Best Carry Player 4ShiinaMahiru#WA 42ms5680kbC++171.4kb2024-10-26 15:19:282024-10-26 15:19:28

Judging History

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

  • [2024-10-26 15:19:28]
  • 评测
  • 测评结果:WA
  • 用时:42ms
  • 内存:5680kb
  • [2024-10-26 15:19:28]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
using i64 = long long;
using ll = long long;
using namespace std;
constexpr int N = 5e5 + 10;

int m;
int a[N],b[N];
void solve(){
    cin >> m;
    for(int i=0; i<m; ++i)cin >> a[i];
    for(int i=0; i<m; ++i)cin >> b[i];
    a[m] = b[m] = 0;
    ll res = 0;
    int t = 0;
    auto cal = [&](){
        for(int i=m-1, j=1; i>0; --i){
            if(!a[i])continue;
            if(b[0] && i + t >= m){
                int d = min(a[i], b[0]);
                b[0] -= d;
                a[i] -= d;
                res += d;
                ++i;
                t = 1;
                continue;
            }
            while(j < m && (i + j + t < m || !b[j]))++j;
            if(!b[j])break;
            if(t == 0){
                t = 1;
                ++res;
                a[i]--, b[j]--;
                ++i;
                continue;
            }
            int d = min(a[i], b[j]);
            res += d;
            a[i] -= d;
            b[j] -= d;
            t = 1;
            if(a[i])++i;
        }
    };
    cal();
    for(int i=0; i<m; ++i)swap(a[i], b[i]);
    cal();
    if(a[m-1] && t)res += a[m-1];
    if(b[m-1] && t)res += b[m-1];
    cout << res << endl;
}

signed main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while(t--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 42ms
memory: 5680kb

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:

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

result:

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