QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#306888#8057. Best Carry Player 4installb#WA 80ms16076kbC++142.2kb2024-01-17 15:09:552024-01-17 15:09:55

Judging History

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

  • [2024-01-17 15:09:55]
  • 评测
  • 测评结果:WA
  • 用时:80ms
  • 内存:16076kb
  • [2024-01-17 15:09:55]
  • 提交

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],s_B[M];
ll f[M][3];//-1,0,+1
int pre[M];
ll solve(){
    for(int i=0;i<=m+1;i++){
        C[i] = f[i][0] = f[i][1] = f[i][2] = s[i]=0;
        s_B[i] = pre[i]=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];
    }
    s_B[0] = B[0];
    for(int i=1;i<m;i++)
        s_B[i] = s_B[i-1] + B[i];
    for(int i=m-1;i>=0;i--)
        if(A[i])pre[i] = i;
        else pre[i] = pre[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(pre[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]);

        if(pre[i] == m-1){
            val += A[pre[i]]-1;
        }else{
            hv += s_B[pre[i]] - s_B[i-1];
            val += min(hv,A[pre[i]]-1);
            hv -= min(hv,A[pre[i]]-1);
            
            if(hv == C[pre[i]+1]-1)val += f[pre[i]+1][0];
            else if(hv == C[pre[i]+1])val += f[pre[i]+1][1];
            else if(hv == C[pre[i]+1]+1)val += f[pre[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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 16076kb

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: 80ms
memory: 16048kb

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

result:

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