QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740917 | #8057. Best Carry Player 4 | prime-ideal | WA | 39ms | 5664kb | C++14 | 1.6kb | 2024-11-13 12:19:08 | 2024-11-13 12:19:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define RN return
#define forw(_,l,r) for(auto _=(l);_<(r);++_)
#define fors(_,r,l) for(auto _=(r);_>(l);--_)
#define fastio cin.tie(0),cout.tie(0),ios::sync_with_stdio(0);
typedef long long ll;
#define int ll
const int NUM=5e5+10;
int ls1[NUM],ls2[NUM],*a,*b;
int m,n1,n2;
void clear(){
n1=n2=0;
a=ls1,b=ls2;
}
ll calc(){
int pt1=m-1,pt2=0,pt3=1;
bool carry=0;
while(pt1>=0&&a[pt1]==0)--pt1;
if(pt1==-1)RN 0;
while(pt3<m&&(b[pt3]==0||pt1+pt3<m))++pt3;
if(pt3==m)RN 0;
--a[pt1],--b[pt3],carry=1;
ll ans=1;
while(pt1>=0){
if(a[pt1]==0){
--pt1;continue;
}
while(pt2<m&&(b[pt2]==0||pt2+pt1<m-1))++pt2;
if(pt2==m){
carry==0;
break;
}
int mi=min(a[pt1],b[pt2]);
// cout<<"---"<<mi<<'\n';
ans+=mi,a[pt1]-=mi,b[pt2]-=mi;
if(a[pt1]==0)--pt1;
if(b[pt2]==0)++pt2;
}
if(carry){
ans+=b[m-1];
}
RN ans;
}
void test(){
}
signed main()
{
fastio;
int t; cin>>t;
forw(_,0,t){
cin>>m;
clear();
forw(i,0,m){
cin>>ls1[i];
n1+=ls1[i];
}
forw(i,0,m){
cin>>ls2[i];
n2+=ls2[i];
}
if(_==22){
forw(i,0,m)cout<<ls1[i]<<' ';
forw(i,0,m)cout<<ls2[i]<<' ';
}
if(n1>n2){
swap(a,b),swap(n1,n2);
}
cout<<calc()<<'\n';
}
RN 0;
}
/*
2
3
0 0 0
0 0 0
3
0 1 1
1 1 1
0
5
1 1 1 1 1
0 1 1 1 1
1
2
1 2
3 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5620kb
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: 39ms
memory: 5664kb
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 0 0 1 1 0 1 1 0 1 2 3 0 3 1 0 2 3 3 1 5 0 0 2 0 0 1 1 0 0 3 4 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 2 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 2 2 2 2 2 0 2 0 0 2 3 1 2 1 ...
result:
wrong answer 23rd numbers differ - expected: '4', found: '0'