QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#755448#8057. Best Carry Player 4Kalimos#WA 16ms5940kbC++141.4kb2024-11-16 17:22:282024-11-16 17:22:28

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 17:22:28]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:5940kb
  • [2024-11-16 17:22:28]
  • 提交

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 = 0;int f = 1;char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f *= -1;
	for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
	x *= f;
}

int a[500050];
int b[500050];

void solve() {
	int m;
	read(m);
	int end1 = 0, end2 = 0;
	int sum1 = 0, sum2 = 0;
	for (int i = 0;i < m;++i) {
		read(a[i]);
		if (a[i]) end1 = i;
		sum1 += a[i];
	}
	for (int i = 0;i < m;++i) {
		read(b[i]);
		if (b[i]) end2 = i;
		sum2 += b[i];
	}

	int end22 = end2;

	if (sum1 > sum2) {
		b[0] += sum1 - sum2;
	}
	else {
		a[0] += sum2 - sum1;
	}

	int ans = 0;
	int f = 0;

	for (int i = 0;i <= end1;++i) {
		if (a[i]) {
			for (int j = end2;j >= 0;--j) {
				if (b[j] && i + j >= m - 1) {
					if (i + j > m - 1) {
						f = 1;
					}
					if (a[i] > b[j]) {
						ans += b[j];
						--end2;
						a[i] -= b[j];
					}
					else {
						ans += a[i];
						b[j] -= a[i];
						break;
					}
				}
			}
		}
	}

	if (f) {
		printf("%lld\n", ans);
	}
	else {
		if (end1 + end22 > m - 1) {
			printf("%lld\n", ans - 1);
		}
		else {
			puts("0");
		}
	}
}

signed main() {
	int t;
	read(t);
	while (t--)
		solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5832kb

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: 16ms
memory: 5940kb

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
0
2
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
1
0
0
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
3
4
0
2
5
0
1
1
0
0
0
2
1
3
0
1
0
4
3
4
0
2
2
0
1
3
1
1
0
0
0
1
0
3
2
2
0
1
0
1
0
1
0
0
2
4
1
2
3
2
2
2
0
1
0
0
2
3
1
3
0
0
2
2
3
0
1
2
0
1
1
...

result:

wrong answer 1st numbers differ - expected: '2', found: '1'