QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#657528 | #8057. Best Carry Player 4 | ucup-team4992# | WA | 67ms | 9868kb | C++20 | 2.0kb | 2024-10-19 14:56:35 | 2024-10-19 14:56:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int M=5e5+5;
ll A[M],B[M],C[M],D[M];
int m;
void solve(){
cin>>m;
int tot1=0,tot2=0;
for(int i=0; i<m; i++) cin>>A[i],C[i]=A[i],tot1+=A[i];
for(int i=0; i<m; i++) cin>>B[i],D[i]=B[i],tot2+=B[i];
A[m]=B[m]=C[m]=D[m]=0;
if(tot1>tot2) B[0]+=tot1-tot2,D[0]+=tot1-tot2;
else A[0]+=tot2-tot1,C[0]+=tot2-tot1;
ll ans=0;
for(int i=0; i<m; i++){
ll a=A[i],b=B[m-1-i];
// cout<<"i = "<<i<<" , a = "<<a<<" , m-1-i = "<<m-1-i<<" , b = "<<b<<"\n";
ll res=min(a,b);
A[i]-=res; B[m-1-i]-=res;
ans+=res;
}
ll ans2=0;
bool flag=0,can=0;
for(int i=1; i<m; i++){
flag|=(B[m-i]>0);
if(flag && A[i]>0){
can=1;
break;
}
}
if(can){
ll tot=0;
for(int i=1; i<m; i++){
tot+=B[m-i];
ll res=min(tot,A[i]);
tot-=res;
ans+=res;
}
cout<<ans+ans2<<"\n";
}else{
flag=0,can=0;
for(int i=1; i<m; i++){
flag|=(B[m-i]>0);
if(flag && C[i]>0){
can=1;
break;
}
}
if(can){
cout<<ans+ans2<<"\n";
return;
}
flag=0,can=0;
for(int i=1; i<m; i++){
flag|=(A[m-i]>0);
if(flag && D[i]>0){
can=1;
break;
}
}
if(can){
cout<<ans+ans2<<"\n";
return;
}
int cnt=0;
for(int i=0; i<m; i++){
ll a=C[i],b=D[m-1-i];
if(a&&b) cnt++;
}
if(cnt<=1){
cout<<"0\n";
return;
}
cout<<max(ans+ans2-1,0ll)<<"\n";
}
return;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9816kb
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: 0
Accepted
time: 40ms
memory: 9808kb
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:
ok 100000 numbers
Test #3:
score: 0
Accepted
time: 25ms
memory: 9744kb
input:
1000 500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
0 1 1 2 2 2 0 0 0 3 1 1 2 0 1 0 1 1 3 0 0 4 3 1 4 4 0 0 2 1 3 3 0 0 1 0 1 1 0 0 2 1 2 0 3 1 3 1 3 4 2 1 1 2 3 0 0 1 2 0 0 1 1 1 1 2 1 2 2 0 2 2 1 1 3 0 0 1 2 0 1 3 0 0 1 1 0 0 1 0 3 1 2 0 0 5 1 1 1 3 1 4 1 0 0 0 0 0 1 3 1 2 1 0 0 0 0 0 1 1 0 4 0 1 1 3 0 1 0 0 2 3 0 1 2 1 1 1 0 3 0 0 3 2 1 1 0 1 0 1 ...
result:
ok 1000 numbers
Test #4:
score: -100
Wrong Answer
time: 67ms
memory: 9868kb
input:
100000 5 119777838 337555280 806504015 458289944 321614229 979242871 431783189 423329635 193632121 7339369 5 189264782 667669243 753322761 861814678 224007583 977519325 104432095 940220826 712094722 903574615 5 977791540 278658984 601762324 633391706 36807634 689562032 997406456 118939957 891425821 ...
output:
1377698543 2884329841 1699584169 1780759937 2531472710 2754014935 1950741996 2577893498 1671531479 1655223784 1476887044 2115933812 1332546839 958870781 600795101 927483202 2136597299 1883468626 2291627593 1436067851 2412405837 1884010446 1960543235 2014856631 848686688 1069641213 2133866856 1597069...
result:
wrong answer 4th numbers differ - expected: '2132012702', found: '1780759937'