QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#534026 | #8057. Best Carry Player 4 | hzjoiineg | WA | 106ms | 5776kb | C++20 | 908b | 2024-08-26 19:23:21 | 2024-08-26 19:23:21 |
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&=!a[i];
rep(i, 1, mx[1]) p&=!b[i];
cout<<ans-p<<endl;
}
return 0;
}
/*
恩偶挨批莫尼塞梯
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5776kb
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: 106ms
memory: 5624kb
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 3 2 0 3 0 2 1 1 0 1 0 4 0 0 2 2 0 3 3 0 2 0 1 0 0 2 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 2 0 0 2 4 1 3 3 2 2 2 0 2 0 0 2 3 1 3 1 0 3 2 3 0 1 2 0 1 1 ...
result:
wrong answer 51st numbers differ - expected: '2', found: '3'