QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591103#8057. Best Carry Player 4zhutianruiWA 38ms9808kbC++141.3kb2024-09-26 14:10:372024-09-26 14:10:38

Judging History

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

  • [2024-09-26 14:10:38]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:9808kb
  • [2024-09-26 14:10:37]
  • 提交

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;
	F(i, 0, m - 1) {
		cin >> a[i], c[i] = 0;
		if (a[i]) mxa = i;
	}
	F(i, 0, m - 1) {
		cin >> b[i], d[i] = 0;
		if (b[i]) mxb = i;
	}
	if (mxa + mxb < m) {
		cout << "0\n";
		return;
	}
	a[0] = b[0] = inf;
	int cnt = 0, jin = 0;
	F(i, 0, m - 1) {
		int x = min(a[i], b[m - 1 - i]);
		a[i] -= x, b[m - 1 - i] -= x;
		cnt += x;
		if (x) c[i] = d[m - 1 - i] = 1;
	}
	dF(i, m - 2, 0) c[i] |= c[i + 1], d[i] |= d[i + 1];
	for (int i = m - 1, j = 1; ~i ; --i) {
		while (a[i] && i + j >= m && j < m) {
			int x = min(a[i], b[j]);
			a[i] -= x, b[j] -= x, jin += x;
			if (!b[j]) j++;
		}
	}
	if (jin) {
		cout << jin + cnt << '\n';
	} else {
		int flag = 0;
		F(i, 1, m - 1) if (a[i] && d[m - i] || b[i] && c[m - i]) flag = 1;
		cout << cnt - 1 + flag << '\n';
	}
}
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;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 9700kb

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: 38ms
memory: 9808kb

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

result:

wrong answer 23rd numbers differ - expected: '4', found: '3'