QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#682646 | #8057. Best Carry Player 4 | ShiinaMahiru | WA | 54ms | 3560kb | C++17 | 2.1kb | 2024-10-27 16:40:11 | 2024-10-27 16:40:12 |
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[0] = b[0] = 2e9 + 10;
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 3560kb
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 4 3 3 2 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 4 3 1 5 0 0 2 0 0 1 1 0 0 3 5 3 2 2 2 0 1 2 2 2 0 4 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 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 5th numbers differ - expected: '3', found: '4'