QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#775561#8057. Best Carry Player 4New_Folder#WA 43ms5708kbC++201.5kb2024-11-23 16:12:562024-11-23 16:12:57

Judging History

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

  • [2024-11-23 16:12:57]
  • 评测
  • 测评结果:WA
  • 用时:43ms
  • 内存:5708kb
  • [2024-11-23 16:12:56]
  • 提交

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];
		fuck[i] = a[i] > 0;
	}
	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]);
		}
	}
	int minn = m, last = -1, aa, bb;
	for(int i = 1; i < m; ++i) {
		if(b[m - i] > 0) last = m - i;
		if(a[i] == 0) continue;
		if(last != -1) {
			if(minn > i + last - m || (minn == i + last - 1 && last != m - 1)) {
				minn = i + last - m;
				aa = i;
				bb = last;
			}
		}
	}
	if(minn == m) {
		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;
	}
	ll sum = 0, ress = 0;
	int ok = 0;
	bool dmm = 0;
	for(int i = 1; i < m; ++i) {
		sum += b[m - i];
		ll tmp = min(sum, a[i]);
		ok = ok | (fuck[i] & (sum > 0));
		if((fuck[i] & (sum > 0)) && sum > b[m - 1]) {
			dmm = 1;
		}
	}
	if(!ok) {
		cout << res - 1 << '\n';
	}
	else {
		ll sum = 0, ress = 0;
		for(int i = 0; i < m; ++i) {
			sum += b[m - i - 1];
			ll tmp = min(sum, a[i]);
			ress += tmp;
			sum -= tmp;
		}
		cout << ress + res + b[m - 1] - 1 + dmm << '\n';
	}
}

int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;cin>>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: 5636kb

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: 5708kb

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

result:

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