QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#330631 | #8057. Best Carry Player 4 | ucup-team1303# | WA | 279ms | 3564kb | C++14 | 1.8kb | 2024-02-17 17:23:34 | 2024-02-17 17:23:34 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T& x, T y) { x = max(x, y); }
template <typename T> void chkmin(T& x, T y) { x = min(x, y); }
template <typename T> void read(T &x) {
x = 0; int f = 1; char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x *= f;
}
const int N = 5e5 + 10;
int n, a[N], b[N], s1, s2;
bool check(int x) {
vector <pair <int, int>> v1, v2;
int t = x;
DF(i, n - 1, 0) if (a[i]) {
int k = min(t, a[i]);
v1.emplace_back(i, k);
t -= k;
if (!t) break;
}
t = x;
DF(i, n - 1, 0) if (b[i]) {
int k = min(t, b[i]);
v2.emplace_back(i, k);
t -= k;
if (!t) break;
}
reverse(all(v2));
bool flag = false;
for (int i = 0, j = 0; i <= SZ(v1); ) {
int t = min(v1[i].second, v2[j].second);
if (v1[i].first + v2[j].first >= n) flag = true;
if (v1[i].first + v2[j].first < n - 1) return false;
if (!(v1[i].second -= t)) i++;
if (!(v2[j].second -= t)) j++;
}
return flag;
}
void zhk() {
read(n);
s1 = s2 = 0;
F(i, 0, n - 1) read(a[i]), s1 += a[i];
F(i, 0, n - 1) read(b[i]), s2 += b[i];
a[0] += 1e9, b[0] += 1e9;
s1 += 1e9, s2 += 1e9;
int l = 0, r = min(s1, s2) + 1;
while (l + 1 < r) {
int mid = (l + r) >> 1;
if (check(mid)) l = mid;
else r = mid;
}
// debug << s1 << " " << s2 << endl;
cout << l << '\n';
}
signed main() {
int _;
read(_);
while (_--) zhk();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3564kb
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: 279ms
memory: 3520kb
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'