QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#591183 | #8057. Best Carry Player 4 | zhutianrui | WA | 59ms | 5668kb | C++14 | 1.2kb | 2024-09-26 14:39:29 | 2024-09-26 14:39:29 |
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];
void solve(int TC) {
cin >> m;
int mxa = 0, mxb = 0, sa = 0, sb = 0;
F(i, 0, m - 1) {
cin >> a[i], sa += a[i];
if (a[i]) mxa = i;
}
F(i, 0, m - 1) {
cin >> b[i], 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;
for(int i = 0, j = m - 1; i < m; ++i)
while(a[i] && i + j >= m - 1) {
while (j && !b[j]) j--;
if (i + j >= m - 1) {
int w = min(a[i], b[j]);
a[i] -= w, b[j] -= w, cnt += w;
if (i + j >= m) flag = 0;
}
}
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
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5624kb
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: 59ms
memory: 5668kb
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'