QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#591153 | #8057. Best Carry Player 4 | hcysxnn# | WA | 72ms | 9812kb | C++14 | 1.3kb | 2024-09-26 14:31:31 | 2024-09-26 14:31:32 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define F(i, a, b) for (int i = (a); i <= (b); i++)
#define dF(i, a, b) for (int i = (a); i >= (b); i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 500005, M = (N << 1), inf = 1e16, mod = 1e9 + 7;
int n, m, a[N], b[N], c[N], d[N];
void solve(int TC) {
cin >> m;
int mxa = 0, mxb = 0, sa = 0, sb = 0;
F(i, 0, m - 1) {
cin >> a[i], c[i] = 0, sa += a[i];
if (a[i]) mxa = i;
}
F(i, 0, m - 1) {
cin >> b[i], d[i] = 0, sb += b[i];
if (b[i]) mxb = i;
}
if (mxa + mxb < m) {
cout << "0\n";
return;
}
if (sa > sb) b[0] += sa - sb;
else a[0] += sb - sa;
int cnt = 0, flag = 1;
dF(i, m - 2, 0) c[i] |= c[i + 1], d[i] |= d[i + 1];
for (int i = m - 1, j = 0; ~i ; --i) {
while (i + j < m - 1 && j < m) j++;
while (a[i] && i + j >= m - 1 && j < m) {
int x = min(a[i], b[j]);
if (i + j >= m) flag = 0;
a[i] -= x, b[j] -= x, cnt += x;
if (!b[j]) j++;
}
}
F(i, 1, m - 1) if (a[m - i] || b[m - i]) flag = 0;
cout << cnt - flag << endl;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T;
cin >> T;
for (int i = 1; i <= T; i ++) {
solve(i);
}
return 0;
}
// g++ x.cpp -o a -O2 -std=c++14 -fsanitize=undefined,address
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 9812kb
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: 72ms
memory: 9724kb
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 3 2 0 3 0 2 1 1 0 1 0 4 0 0 2 2 0 3 3 0 2 0 1 0 0 2 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 2 0 0 2 4 1 3 3 2 2 2 0 2 0 0 2 3 1 3 1 0 3 2 3 0 1 2 0 1 1 ...
result:
wrong answer 51st numbers differ - expected: '2', found: '3'