QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#755975 | #8057. Best Carry Player 4 | Kalimos# | WA | 54ms | 6000kb | C++23 | 1.6kb | 2024-11-16 18:34:48 | 2024-11-16 18:34:48 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS 1
#pragma warning(disable:6031)
#include<bits/stdc++.h>
using namespace std;
#define int long long
template <typename T> void read(T& x) {
x = 0ll;int f = 1ll;char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f *= -1ll;
for (; isdigit(c); c = getchar()) x = (x << 3ll) + (x << 1ll) + c - '0';
x *= f;
}
int a[500050];
int b[500050];
void solve() {
int m;
scanf("%lld", &m);
int end1 = 0, end2 = 0;
int sum1 = 0, sum2 = 0;
for (int i = 0;i < m;i++) {
scanf("%lld", &a[i]);
if (a[i]) end1 = i;
}
for (int i = 0;i < m;i++) {
scanf("%lld", &b[i]);
if (b[i]) end2 = i;
}
if (end1 < end2) {
for (int i = 0;i < m;i++) {
swap(a[i], b[i]);
}
swap(end1, end2);
}
for (int i = 0;i < m;i++) {
sum1 += a[i];
sum2 += b[i];
}
if (sum1 > sum2) {
b[0] += sum1 - sum2;
}
else {
a[0] += sum2 - sum1;
}
int ans = 0;
int temp = 0;
int f = 0;
for (int i = m - end1;i <= end2;i++) {
if (b[i]) {
++ans;
f = 1;
--a[end1];
--b[i];
break;
}
}
if (!f) {
puts("0");
return;
}
for (int i = end1;i >= 0;i--) {
if (a[i]) {
for (int j = max(temp, m - i - 1);j <= end2;j++) {
if (b[j]) {
if (b[j] >= a[i]) {
ans += a[i];
b[j] -= a[i];
a[i] = 0;
temp = j;
break;
}
else {
ans += b[j];
a[i] -= b[j];
b[j] = 0;
temp = j + 1;
}
}
}
}
}
printf("%lld\n", ans);
}
signed main() {
int t;
scanf("%lld", &t);
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6000kb
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: 5896kb
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:
1 0 4 0 3 3 3 2 0 0 1 1 2 0 3 0 0 0 0 0 0 0 3 0 4 1 0 2 3 2 1 4 0 0 2 0 0 1 1 0 0 3 4 3 1 2 2 0 1 2 2 2 0 3 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 2 4 0 2 5 0 1 1 0 0 0 2 1 3 0 2 0 4 3 3 0 2 1 0 1 3 1 1 0 0 0 1 0 3 1 1 0 2 1 1 0 1 0 0 2 4 1 3 2 1 2 1 0 1 0 0 2 3 1 3 1 0 2 1 3 0 1 2 0 1 1 ...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'