QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#366980#8057. Best Carry Player 4FengfengWA 51ms3824kbC++201.9kb2024-03-25 15:32:012024-03-25 15:32:03

Judging History

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

  • [2024-03-25 15:32:03]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:3824kb
  • [2024-03-25 15:32:01]
  • 提交

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];
    }
    if(s1>s2){
        swap(a,b);
    }


    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];
    }
    a[0]+=b[n-1];
    long long t=min(a[0],b[n-1]);
    mp[0]+=t;
    a[0]-=t;b[n-1]-=t;
    sum+=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;
        }
    }
    if(sum==mp[0]||sum==mp[n-1]){
        cout<<0<<'\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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

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

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
0
0
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
0
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
0
1
1
...

result:

wrong answer 168th numbers differ - expected: '0', found: '1'