QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630253 | #8057. Best Carry Player 4 | Rilllo# | WA | 38ms | 7740kb | C++23 | 1.8kb | 2024-10-11 17:20:52 | 2024-10-11 17:20:52 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define Pa pair<int,int>
using namespace std;
const int N=2e6+10,mod=1e9+7;
int a[N],b[N],c[N],d[N];
int m;
void solve(){
cin>>m;
int mx=0;
bool flag= false;
for(int i=0;i<=m-1;i++){
cin>>a[i];
if(a[i]){
mx=max(mx,i);
}
}
for(int i=0;i<=m-1;i++){
cin>>b[i];
if(b[i]){
if(i+mx>=m)flag= true;
}
}
if(!flag){
cout<<0<<'\n';
return;
}
// int mn=1e10;
int ans=0;
int l=1;
bool f= false;
for(int i=m-2;i>=1;i--){
while(a[i]&&l<m-1){
while(l+i<m-1)l++;
if(l>=m-1)break;
int minn=min(a[i],b[l]);
if(i+l>=m)f= true;
a[i]-=minn;
ans+=minn;
b[l]-=minn;
if(!b[l])l++;
}
if(l>=m-1)break;
}
int s1=0,s2=0;
// for(int i=0;i<=m-1;i++)cout<<a[i]<<' ';
// cout<<'\n';
// for(int i=0;i<=m-1;i++)cout<<b[i]<<' ';
// cout<<'\n';
for(int i=0;i<m-1;i++){
s1+=a[i];
if(a[i]&&i>0&&b[m-1]){
f= true;
}
}
for(int i=0;i<m-1;i++){
s2+=b[i];
if(b[i]&&i>0&&a[m-1]){
f= true;
}
}
int mn1=min(s1,b[m-1]);
int mn2=min(s2,a[m-1]);
ans+=mn1+mn2;
a[m-1]-=mn2;
b[m-1]-=mn1;
ans+=max(a[m-1],b[m-1]);
if(a[m-1]&&b[m-1])f= true;
// cout<<f<<' ';
// cout<<ans<<' ';
if(!f)ans--;
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T=1;cin>>T;
while(T--)solve();
}
//1
//10
//5 3 5 3 2 4 2 4 1 5
//9 9 8 2 4 4 3 5 3 0
//5 1 0 0 0 0 0 0 0 5
//9 8 4 0 0 2 0 1 0 0
//23
//28
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7684kb
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: 38ms
memory: 7740kb
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 0 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 2 2 3 0 1 2 0 1 0 ...
result:
wrong answer 57th numbers differ - expected: '1', found: '0'