QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#755252#8057. Best Carry Player 4Kalimos#WA 15ms5928kbC++141.4kb2024-11-16 16:51:412024-11-16 16:51:43

Judging History

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

  • [2024-11-16 16:51:43]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:5928kb
  • [2024-11-16 16:51:41]
  • 提交

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 sum = 0;
	for (int i = 0;i < m;++i) {
		read(a[i]);
		if (a[i]) end1 = i;
	}
	for (int i = 0;i < m;++i) {
		read(b[i]);
		if (b[i]) end2 = i;
	}
	if (end1 == 0 || end2 == 0) {
		puts("0");
		return;
	}
	if (end1 < end2) {
		for (int i = 0;i < m;++i) {
			swap(a[i], b[i]);
		}
	}

	for (int i = 0;i < m;++i) {
		sum += b[i];
	}

	a[0] = sum;

	int ans = 0;
	int temp = 0;
	for (int i = m - end1;i < m;++i) {
		if (b[i]) {
			++ans;
			--a[end1];
			--b[i];
			break;
		}
	}


	for (int i = end1;i >= 0;--i) {
		if (a[i]) {
			for (int j = max(temp, m - i - 1);j < m;++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;
	read(t);
	while (t--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

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: 15ms
memory: 5928kb

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

result:

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