QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#366959#8057. Best Carry Player 4FengfengWA 52ms3628kbC++201.6kb2024-03-25 15:11:192024-03-25 15:11:20

Judging History

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

  • [2024-03-25 15:11:20]
  • 评测
  • 测评结果:WA
  • 用时:52ms
  • 内存:3628kb
  • [2024-03-25 15:11:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
long long ksm(long long a,long long b,long long mod){
    long long res=1;
    a%=mod;
    while(b){
        if(b&1) res=res*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return res;
}

void solve(){
    int n;
    cin>>n;
    vector<long long>a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    a[0]+=1e9;
    b[0]+=1e9;
    vector<long long>mp(n);
    long long sum=0;
    for(int i=0;i<n;i++){
        mp[i]=min(a[i],b[n-1-i]);
        sum+=mp[i];
        a[i]-=mp[i];b[n-i-1]-=mp[i];
    }
    //凑n-1
    long long ans=0;
    int r=n-1;
    for(int i=1;i<n&&r>=0;i++){
        while(i+r>=n&&a[i]){
            long long t=min(a[i],b[r]);
            ans+=t;
            b[r]-=t;a[i]-=t;
            while(r>=0&&b[r]==0){
                r--;
            }
        }
    }
    if(ans){
        cout<<ans+sum<<'\n';
        return;
    }
    if(ans==0&&sum==0){
        cout<<0<<'\n';
        return;
    }
    for(int i=1;i<n;i++){
        a[i]+=a[i-1];
        b[i]+=b[i-1];
    }
    for(int i=0;i<n;i++){
        if(mp[i]==0) continue;
        int l=i,r=n-1-i;
        //x+l>=n 
        int x=n-l-1;
        int y=n-r-1;
        if(b[n-1]-(x>=0?b[x]:0)>0||a[n-1]-(y>=0?a[y]:0)){
            cout<<sum<<'\n';
            return;
        }
    }
    cout<<sum-1<<'\n';

}

int main(){
    ios::sync_with_stdio(false);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: 3628kb

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: 3616kb

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
4
3
3
2
0
0
1
1
3
0
3
0
0
0
0
0
0
0
4
0
4
1
0
2
4
3
1
5
0
0
2
0
0
1
1
0
0
3
5
3
2
2
2
0
1
2
2
2
0
4
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 5th numbers differ - expected: '3', found: '4'