QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#341624 | #8057. Best Carry Player 4 | Vengeful_Spirit# | WA | 44ms | 9840kb | C++14 | 2.0kb | 2024-02-29 20:10:48 | 2024-02-29 20:10:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 5e5+5;
ll a[MN], b[MN], r[MN];
bool ua[MN], ub[MN];
int getr(int i) {
if(r[i] == i) return i;
return r[i] = getr(r[i]);
}
void solve() {
int m;
cin >> m;
long long _1 = 0, _2 = 0;
for(int i = 0; i < m; ++i) cin >> a[i], ua[i] = 0, _1 += a[i];
for(int i = 0; i < m; ++i) cin >> b[i], ub[i] = 0, _2 += b[i];
// cal num9
long long num9 = 0, num10 = 0;
if(_1 < _2) a[0] += _2 - _1;
if(_2 < _1) b[0] += _1 - _2;
for(int i = 0; i < m; ++i) {
ll cc = min(a[i], b[m-1-i]);
num9 += cc;
a[i] -= cc;
b[m-1-i] -= cc;
if(cc) ua[i] = ub[m-1-i] = 1;
}
for(int i = 0; i < m; ++i) r[i] = i;
for(int i = m-1; i; --i) {
int j = m-i; j = getr(j);
while(j < m) {
// cout << i << " " << j << " " << num10 << "\n";
ll cc = min(a[i], b[j]);
num10 += cc;
a[i] -= cc;
b[j] -= cc;
if(b[j] > 0) break;
if(j == m-1) break;
r[j] = getr(j+1);
j = r[j];
}
}
// cout << num9 << " " << num10 << " ";
if(num10 == 0) {
bool fl = 0, aa = 0, bb = 0;
for(int i = 0; i < m; ++i) {
if(aa && a[i]) {fl = 1; break;}
if(bb && b[i]) {fl = 1; break;}
aa |= ua[i];
bb |= ub[i];
}
if(fl) cout << num9 << "\n";
else cout << max(0ll, num9 - 1) << "\n";
} else {
cout << num9 + num10 << "\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
// freopen("in.txt", "r", stdin);
int T;
cin >> T;
while(T--) solve();
return 0;
}
/*
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
*/
/*
5
1
2
467900
29
*/
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 9840kb
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: 44ms
memory: 7724kb
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 2 2 0 3 0 2 1 1 0 1 0 4 1 1 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 1 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 1 1 1 ...
result:
wrong answer 63rd numbers differ - expected: '0', found: '1'