QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#546048 | #8057. Best Carry Player 4 | Fluoresce | WA | 46ms | 9804kb | C++20 | 1.8kb | 2024-09-03 19:13:07 | 2024-09-03 19:13:08 |
Judging History
answer
#include<bits/stdc++.h>
#include<unordered_map>
typedef long long ll;
typedef long double ld;
#define debug(a) cout<<a<<'\n'
#define Pll pair<ll,ll>
#define PII pair<int,int>
#define ft first
#define sd second
#define pushk push_back
#define popk pop_back
#define vec vector
using namespace std;
const int N = 5e5 + 10, M = 1e7, mod = 998244353;
const ll inf = 1e18;
const ld eps = 1e-8;
int mov[4][2] = { {0,1},{1,0},{-1,0},{0,-1} }, dx, dy;
void bout(bool f) {
if (f)cout << "YES\n";
else cout << "NO\n";
}
ll n, m, k;
ll s1[N],s2[N],a[N],b[N];
void solve() {
cin>>n;
s1[0]=s2[0]=0;
for(int i=0;i<n;++i){
cin>>a[i];
s1[0]+=a[i];
}
for(int i=0;i<n;++i){
cin>>b[i];
s2[0]+=b[i];
}
a[0]+=max(s1[0],s2[0])-s1[0];
b[0]+=max(s1[0],s2[0])-s2[0];
s1[0]=a[0];
s2[0]=b[0];
for(int i=1;i<n;++i){
s1[i]=s1[i-1]+a[i];
s2[i]=s2[i-1]+b[i];
}
bool f=0;
int l=0,r=n-1;
ll ans=0,res;
while(l<=n-1){
while(a[l]&&l+r>=n-1){
if(!b[r])--r;
else{
if(l+r>=n)f=1;
res=min(a[l],b[r]);
ans+=res;
a[l]-=res;
b[r]-=res;
}
}
++l;
}
for(int i=0;i<n;++i){
if(a[i]&&s2[n-1]-s2[n-1-i])f=1;
if(b[i]&&s1[n-1]-s1[n-1-i])f=1;
}
if(f)cout<<ans<<'\n';
else{
for(int i=n-1;i>=(n+1)/2;--i){
if(s1[n-1]-s1[i-1]&&s2[n-1]-s2[i-1])f=1;
}
if(f)cout<<max((ll)0,ans-1)<<'\n';
else cout<<0<<'\n';
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
streambuf* cinbackup = cin.rdbuf(), * coubackup = cout.rdbuf();
ifstream fin("in.txt");
ofstream fout("out.txt");
cin.rdbuf(fin.rdbuf());
cout.rdbuf(fout.rdbuf());
#endif
int _ = 1, __ = 1;
cin >> _;
__ = _;
while (_--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9796kb
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: 46ms
memory: 9804kb
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 0 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 0 0 0 0 1 2 0 3 4 0 2 5 0 2 1 0 0 0 3 2 0 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 0 0 0 0 4 1 3 3 2 2 2 0 2 0 0 2 3 1 3 1 0 0 2 3 0 0 2 0 0 1 ...
result:
wrong answer 26th numbers differ - expected: '1', found: '0'