QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#711966#8057. Best Carry Player 4acwing_gza#WA 159ms9700kbC++201.6kb2024-11-05 14:10:002024-11-05 14:10:00

Judging History

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

  • [2024-11-05 14:10:00]
  • 评测
  • 测评结果:WA
  • 用时:159ms
  • 内存:9700kb
  • [2024-11-05 14:10:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef ll i64;
typedef __int128 i128;
constexpr int maxn=5e5+9;
int m;
i64 a[maxn],b[maxn];
i64 ta[maxn],tb[maxn];
ll suma,sumb;
void solve()
{
    cin>>m;
    int n=m; suma=sumb=0;
    for(int i=0;i<m;++i) cin>>a[i],suma+=ta[i]=a[i];
    for(int i=0;i<m;++i) cin>>b[i],sumb+=tb[i]=b[i];
    // printf("suma=%lld sumb=%lld\n",suma,sumb);
    if(suma>sumb)
    {
        for(int i=0;i<m;++i) swap(a[i],b[i]);
        swap(suma,sumb);
    }
    a[0]+=sumb-suma;
    int ptr=m-1;
    ll ans=0;
    int flag=0,flag2=0;
    ll ss=0;
    for(int i=0;i<m;++i)
    {
        ss+=b[m-i];
        if(ss && a[i]) { flag2=1; break; }
    }
    for(int i=0;i<m;++i)
    {
        while(ptr>=0 && i+ptr>=m-1 && a[i]>=b[ptr])
        {
            // printf("match %lld of %d in a and %d in b\n",b[ptr],i,ptr);
            if(i+ptr>=m) flag=1;
            ans+=b[ptr];
            a[i]-=b[ptr]; b[ptr]=0;
            --ptr;
        }
        if(ptr>=0 && i+ptr>=m-1 && a[i])
        {
            // printf("match %lld of %d in a and %d in b\n",a[i],i,ptr);
            if(i+ptr>=m) flag=1;
            ans+=a[i];
            b[ptr]-=a[i]; a[i]=0;
        }
    }
    int tmp=-1;
    for(int i=0;i<m;++i)
        if(ta[i]>a[i]) {
            tmp=i;
            break;
        }
    for(int i=tmp+1;i<m;++i)
        if(a[i]) flag=1;
    cout<<(flag?ans:(flag2==0?0:ans-1))<<endl;
}
int main()
{
    // ios::sync_with_stdio(0);
    // 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: 9676kb

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: 159ms
memory: 9700kb

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
1
3
0
0
0
0
1
0
1
4
0
4
1
0
2
3
3
1
5
1
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
0
2
0
3
4
0
2
5
0
2
1
0
0
0
3
2
3
0
2
1
4
3
3
1
2
2
2
1
3
1
1
0
0
0
1
0
3
2
2
0
2
1
1
0
1
0
0
2
4
1
2
3
2
2
2
0
2
0
1
2
3
1
3
1
0
2
2
3
0
1
2
0
1
1
...

result:

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