QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#306879#8057. Best Carry Player 4installb#WA 73ms12024kbC++142.0kb2024-01-17 14:55:442024-01-17 14:55:44

Judging History

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

  • [2024-01-17 14:55:44]
  • 评测
  • 测评结果:WA
  • 用时:73ms
  • 内存:12024kb
  • [2024-01-17 14:55:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define M 500005
using ll = long long;
int m;
ll A[M],B[M];
ll C[M],s[M];
ll f[M][3];//-1,0,+1
ll solve(){
    for(int i=0;i<=m;i++)
        C[i] = f[i][0] = f[i][1] = f[i][2]=0;
    reverse(B,B+m);
    C[0] = 0;
    ll res = 0;
    for(int i=0;i<m;i++){
        res += B[i];
        s[i] = max(res-A[i],0ll) + (i==0?0ll:s[i-1]);
        C[i+1] = max(res-A[i],0ll);
        res = C[i+1];
    }
    for(int i=m-1;i>=0;i--){//-1,0,+1
        for(int c=-1;c<=1;c++){
            ll gv = max(0ll,c+C[i]) + B[i];
            f[i][c+1] = min(gv,A[i]);
            if(i == m-1 && gv < A[i])
                f[i][c+1] += A[i]-gv;
            gv -= min(gv,A[i]);
            if(gv == C[i+1]-1)f[i][c+1] += f[i+1][0];
            else if(gv == C[i+1])f[i][c+1] += f[i+1][1];
            else if(gv == C[i+1]+1)f[i][c+1] += f[i+1][2];
            else assert(0);
        }
    }
    ll ans = 0;
    for(int i=1;i<m;i++)if(A[i]>0 && B[i-1]>0){
        ll val = i==1?0:s[i-2],hv = C[i-1];
        hv += B[i-1]-1;
        val += min(hv,A[i-1]);
        hv -= min(hv,A[i-1]);
        // cout<<hv<<' '<<val<<endl;
        if(i == m-1){
            val += A[i]-1;
        }else{
            hv += B[i];
            val += min(hv,A[i]-1);
            hv -= min(hv,A[i]-1);
            
            if(hv == C[i+1]-1)val += f[i+1][0];
            else if(hv == C[i+1])val += f[i+1][1];
            else if(hv == C[i+1]+1)val += f[i+1][2];
            else assert(0);
        }
        ans = max(ans, val+1);
    }
    reverse(B,B+m);
    return ans;
}
int main(){
    int Cas;
    cin>>Cas;
    while(Cas--){
        scanf("%d",&m);
        for(int i=0;i<m;i++)
            scanf("%lld",&A[i]);
        for(int i=0;i<m;i++)
            scanf("%lld",&B[i]);
        ll ans = solve();
        for(int i=0;i<m;i++)swap(A[i],B[i]);
        ans = max(ans,solve());
        printf("%lld\n",ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 73ms
memory: 12016kb

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
5
0
6
0
5
0
0
0
2
1
3
0
4
0
0
0
0
0
0
0
4
0
3
0
0
4
5
5
0
9
0
0
5
0
0
1
1
0
0
5
5
4
10
3
2
0
2
0
0
2
0
0
0
3
0
1
0
4
0
4
0
0
0
2
0
3
5
0
4
0
0
0
0
1
1
2
0
0
4
0
3
8
0
2
2
0
0
0
3
3
3
0
4
0
4
3
5
0
0
2
0
1
8
1
1
0
0
0
0
0
6
2
0
0
0
0
2
0
1
0
0
0
6
1
0
0
2
0
4
0
3
0
0
0
4
0
4
1
0
2
0
3
0
1
2
0
0
1...

result:

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