QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#366968#8057. Best Carry Player 4FengfengWA 51ms3604kbC++201.9kb2024-03-25 15:23:072024-03-25 15:23:07

Judging History

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

  • [2024-03-25 15:23:07]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:3604kb
  • [2024-03-25 15:23:07]
  • 提交

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);
    long long s1=0,s2=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        s1+=a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
        s2+=b[i];
    }

    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];
    }
    if(s1>s2){
        b[0]+=a[n-1];
    }
    else{
        a[0]+=b[n-1];
    }
    long long t=min(a[0],b[n-1]);
    mp[0]+=t;
    sum+=t;
    a[0]-=t;
    b[n-1]-=t;
    t=min(a[n-1],b[0]);
    mp[n-1]+=t;
    sum+=t;
    a[n-1]-=t;
    b[0]-=t;
    //凑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;
        x=max(x,0);y=max(y,0);
         if(b[n-1]-b[x]>0||a[n-1]-a[y]>0){
            cout<<sum<<'\n';
            return;
        }
    }
    cout<<sum-1<<'\n';

}
/*
1
5
0 1 0 1 1
0 0 1 1 1
*/
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: 3488kb

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: 51ms
memory: 3604kb

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