QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#691494 | #8057. Best Carry Player 4 | xxk2006 | WA | 16ms | 7720kb | C++23 | 1.8kb | 2024-10-31 11:39:21 | 2024-10-31 11:39:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define Enter putchar('\n')
#define spc putchar(' ')
#define pb push_back
#define fi first
#define se second
inline void read(int &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
inline void lread(long long &num){num=0;int f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){num=(num<<1)+(num<<3)+(ch^48);ch=getchar();}num*=f;}
void print(long long num){if(num<0){putchar('-');num=-num;}if(num>9){print(num/10);}putchar((num%10)^48);}
const int N=5e5+9;
LL a[N],b[N],g[N];
set<int> s;
int main(){
int T,n;
read(T);
while(T--){
read(n);
LL s1=0,s2=0;
for(int i=0;i<n;i++){
lread(a[i]);
s1+=a[i];
}
for(int i=0;i<n;i++){
lread(b[i]);
s2+=b[i];
}
if(s2>s1){
for(int i=0;i<n;i++)swap(a[i],b[i]);
swap(s2,s1);
}
b[0]+=s1-s2;
s.clear();
for(int i=1;i<n;i++)if(b[i])s.insert(i);
int mi=1e9,p1,p2;
for(int i=n-1;i;i--){
if(!a[i])continue;
auto it=s.lower_bound(n-i);
if(it!=s.end()&&(*it)-n+i<=mi){
mi=(*it)-n+i;
p1=i,p2=(*it);
}
}
if(mi==1e9){
puts("0");
continue;
}
--a[p1],--b[p2];
LL ans=0,f=n-1;
g[n-1]=b[n-1];
for(int i=n-2;i>=0;i--){
g[i]=g[i+1]+b[i];
}
for(int i=0;i<n;i++){
ans+=min(a[i],g[n-i-1]-ans);
}
print(ans+1),Enter;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7720kb
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: 16ms
memory: 7668kb
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 3 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 3 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 3rd numbers differ - expected: '4', found: '3'