QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#534029 | #8057. Best Carry Player 4 | hzjoiineg | WA | 297ms | 5780kb | C++20 | 948b | 2024-08-26 19:30:09 | 2024-08-26 19:30:09 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, j, k) for(int i=j;i<=k;i++)
#define rep1(i, j, k) for(int i=k;i>=j;i--)
#define ll long long
using namespace std;
const int N=5e5+5;
int T, m, a[N], b[N], mx[2];
ll s[2], ans;
int main(){
cin>>T;
while(T--){
cin>>m;
mx[0]=mx[1]=ans=s[0]=s[1]=0;
rep(i, 0, m-1){
cin>>a[i]; s[0]+=a[i];
if(a[i]) mx[0]=i;
}
rep(i, 0, m-1){
cin>>b[i]; s[1]+=b[i];
if(b[i]) mx[1]=i;
}
if(mx[0]+mx[1]<m){puts("0"); continue;}
if(s[0]>s[1]) b[0]+=s[0]-s[1];
else a[0]+=s[1]-s[0];
int j=m-1; bool p=1;
rep(i, 0, m-1){
while(a[i] && i+j>=m-1){
if(!b[j]){--j; continue;}
int del=min(a[i], b[j]);
a[i]-=del, b[j]-=del, ans+=del, p&=(i+j==m-1);
}
}
rep(i, 1, mx[0]) p&=!b[m-i];
rep(i, 1, mx[1]) p&=!a[m-i];
cout<<ans-p<<endl;
}
return 0;
}
/*
恩偶挨批莫尼塞梯
塞欸死皮杠欸斯莫尼塞梯
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
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: 139ms
memory: 5780kb
input:
100000 5 0 1 1 1 1 0 0 1 0 0 5 0 0 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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: 297ms
memory: 5768kb
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 2132012702 2531472710 2754014935 2585135038 2577893498 2034726862 2303377730 1476887044 2618960687 1626312268 1068946376 600795101 927483202 2151016849 2256729729 2291627593 1751199962 2412405837 1884010446 2553701265 2014856631 848686688 1069641213 2412585811 167144...
result:
wrong answer 39th numbers differ - expected: '1572566306', found: '-1412970174'