QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#775671#8057. Best Carry Player 4New_Folder#WA 43ms5632kbC++201.4kb2024-11-23 16:27:042024-11-23 16:27:04

Judging History

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

  • [2024-11-23 16:27:04]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:5632kb
  • [2024-11-23 16:27:04]
  • 提交

answer

#pragma GCC optimize(2)
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

ll m, a[500005], b[500005];
bool fuck[500005];

void solve(){
	cin >> m;
	ll s1 = 0, s2 = 0;
	for(int i = 0; i < m; ++i) {
		cin >> a[i];
		s1 += a[i];
	}
	for(int i = 0; i < m; ++i) {
		cin >> b[i];
		s2 += b[i];
	}
	if(s1 > s2) {
		for(int i = 0; i < m; ++i) {
			swap(a[i], b[i]);
		}
	}
	for(int i = 0; i < m; ++i) fuck[i] = a[i] > 0;
	int last = -1;
	bool ok = 0;
	for(int i = 1; i < m; ++i) {
		if(b[m - i] > 0) last = m - i;
		if(a[i] == 0) continue;
		if(last != -1) { 
			ok = 1;
		}
	}
	if(!ok) {
		cout << 0 << '\n';
		return;
	}
	ll res = 0;
	for(int i = 0; i < m; ++i) {
		int j = m - i - 1;
		int tmp = min(a[i], b[j]);
		res += tmp;
		a[i] -= tmp;
		b[j] -= tmp;
	}
	ok = 0;
	bool dmm = 0;
	last = m;
	int add = 0;
	for(int i = 1; i < m; ++i) {
		if(b[m - i] > 0) last = m - i;
		if((fuck[i] & (last != m))) {
			ok = 1;
			--b[last];
			if(a[i] > 0) {
				--a[i];add = 1;
			}
			break;
		}
	}
	if(!ok) {
		cout << res - 1 << '\n';
	}
	else {
		ll sum = 0, ress = 0;
		for(int i = 1; i < m; ++i) {
			sum += b[m - i - 1];
			ll tmp = min(sum, a[i]);
			ress += tmp;
			sum -= tmp;
		}
		cout << ress + res + b[m - 1] + add << '\n';
	}
}

int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;cin>>T;while(T--)
	solve();
    return 0;
}

详细

Test #1:

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

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: 43ms
memory: 5632kb

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

result:

wrong answer 5th numbers differ - expected: '3', found: '2'