QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#678788 | #8057. Best Carry Player 4 | ShiinaMahiru# | WA | 54ms | 3748kb | C++17 | 2.1kb | 2024-10-26 16:08:19 | 2024-10-26 16:08:24 |
Judging History
answer
#include<bits/stdc++.h>
#define endl '\n'
using i64 = long long;
using ll = long long;
using namespace std;
constexpr int N = 5e5 + 10;
int m;
void solve(){
cin >> m;
vector<int> a(m+1), b(m+1);
for(int i=0; i<m; ++i)cin >> a[i];
for(int i=0; i<m; ++i)cin >> b[i];
a[m] = b[m] = 0;
auto check = [&](vector<int> a, vector<int> b){
ll res = 0;
int t = 0;
auto cal = [&](){
for(int i=m-1, j=0; i>0; --i){
if(!a[i])continue;
while(j < m && (i + j + t < m || !b[j]))++j;
if(!b[j])break;
if(t == 0){
t = 1;
++res;
a[i]--, b[j]--;
++i;
j = 0;
continue;
}
int d = min(a[i], b[j]);
res += d;
a[i] -= d;
b[j] -= d;
t = 1;
if(a[i])++i;
}
};
cal();
cal();
for(int i=0; i<m; ++i)swap(a[i], b[i]);
cal();
cal();
if(a[m-1] && t)res += a[m-1];
if(b[m-1] && t)res += b[m-1];
return res;
};
ll ans = check(a, b);
int t = 1;
ll res = 0;
bool f = false;
auto cal2 = [&](){
for(int i=m-1, j=0; i>0; --i){
if(!a[i])continue;
while(j < m && (i + j + t < m || !b[j]))++j;
if(!b[j])break;
if(i + j >= m)f = true;
int d = min(a[i], b[j]);
res += d;
a[i] -= d;
b[j] -= d;
t = 1;
if(a[i])++i;
}
};
cal2();
for(int i=0; i<m; ++i)swap(a[i], b[i]);
cal2();
if(a[m-1] && t)res += a[m-1];
if(b[m-1] && t)res += b[m-1];
// cout << res << ' ' << ans << endl;
if(f){
cout << res << endl;
}
else cout << ans << endl;
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while(t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
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: 54ms
memory: 3524kb
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:
1 0 4 0 3 3 3 2 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 3 1 0 2 3 2 1 3 0 0 2 0 0 1 1 0 0 3 3 3 1 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 4 0 2 4 0 1 1 0 0 0 3 1 3 0 2 0 4 3 3 0 2 1 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 1st numbers differ - expected: '2', found: '1'