QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#654304 | #8057. Best Carry Player 4 | zqx# | WA | 47ms | 7724kb | C++23 | 1.5kb | 2024-10-18 21:23:28 | 2024-10-18 21:23:31 |
Judging History
answer
#include<bits/stdc++.h>
#define AC return 0;
#define int long long
#define pii pair<int,int>
#define all(tar) tar.begin(),tar.end()
const int N=1e6+5;
const int mod=998244353;
using namespace std;
int n,m,t,d;
int a[N];
int b[N];
bool use[N];
bool vis[N];
void solve(){
cin>>n;
set<int>st;
int s1=0,s2=0;
for(int i=0;i<n;i++){
cin>>a[i];
s1+=a[i];
use[i]=0;
vis[i]=0;
}
a[n]=0;
b[n]=0;
for(int i=0;i<n;i++){
cin>>b[i];
s2+=b[i];
if(b[i])st.insert(i);
}
if(s1>s2)b[0]+=s1-s2;
else a[0]+=s2-s1;
int pos=0,maxn=1e9;
for(int i=1;i<n;i++){
if(!a[i])continue;
auto it=st.lower_bound(n-i);
if(it==st.end())continue;
int x=*it;
if(x+i<maxn){
maxn=x+i;
pos=i;
}
}
if(pos){
int ans=0;
bool flag=0;
for(int l=0,r=n-1;l<=n-1;){
while(l+r<n-1&&l<=n-1)++l;
ans+=min(a[l],b[r]);
int x=min(a[l],b[r]);
a[l]-=x;
b[r]-=x;
if(x)use[l]=1,vis[r]=1;
if(l+r>=n&&x)flag=1;
while(a[l]==0&&l<=n-1)++l;
while(r>=1&&b[r]==0)--r;
}
for(int i=1;i<n;i++){
if(use[i-1]&&a[i])flag=1;
if(vis[i]&&b[i])flag=1;
use[i]|=use[i-1];
vis[i]|=vis[i-1];
}
if(!flag)ans--;
cout<<ans<<'\n';
}
else cout<<"0\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;cin>>T;
while(T--) solve();
AC
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7724kb
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: 47ms
memory: 7676kb
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 1 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 1 ...
result:
wrong answer 51st numbers differ - expected: '2', found: '3'