QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#359208#8057. Best Carry Player 4CSU2023#WA 44ms5700kbC++141.6kb2024-03-20 14:42:212024-03-20 14:42:21

Judging History

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

  • [2024-03-20 14:42:21]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:5700kb
  • [2024-03-20 14:42:21]
  • 提交

answer

#include <bits/stdc++.h>

using std::ios;
using std::cin;
using std::cout;
typedef long long ll;
const int N = 5e5 + 5;
const int Maxn = 1e9;
int T_data, m;
ll ta, tb, a[N], b[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	cin >> T_data;
	while (T_data--)
	{
		cin >> m;
		ta = tb = 0;		
		for (int i = 0; i < m; ++i)
			cin >> a[i], ta += a[i];
		for (int i = 0; i < m; ++i)
			cin >> b[i], tb += b[i];
		if (ta < tb)
			a[0] += tb - ta;
		if (ta > tb)
			b[0] += ta - tb;
		ll cnt0 = 0, cnt1 = 0, cnt2 = 0;
		int amin = Maxn, bmin = Maxn;
		for (int i = 0, j = m - 1; i < m; ++i)
		{
			while (j > 0 && b[j] == 0)
				--j;
			while (a[i] > 0 && b[j] > 0 && i + j >= m - 1)
			{
				ll temp = std::min(a[i], b[j]);
				a[i] -= temp;
				b[j] -= temp;
				if (i + j >= m)
					cnt0 += temp;
				else 
				{
					++cnt2;
					cnt1 += temp; 
					if (i < amin)
						amin = i;
					if (j < bmin)
						bmin = j; 
				}
				while (j > 0 && b[j] == 0)
				--j;
			}
		}
//		for (int i = 0; i < m; ++i)
//			cout << a[i] << ' ';
//		cout << '\n';
//		for (int i = 0; i < m; ++i)
//			cout << b[i] << ' ';
//		cout << '\n';
		if (cnt0 > 0)
			cout << cnt0 + cnt1 << '\n';
		else
		{
			bool flag = false; 
			for (int i = amin + 1; i < m; ++i)
				if (a[i] > 0)
				{
					flag = true;
					break ;	
				}
			for (int i = bmin + 1; i < m; ++i)
				if (b[i] > 0)
				{
					flag = true;
					break ;
				}
			if (flag)
				cout << cnt0 + cnt1 << '\n';
			else if (cnt2 > 0)
				cout << cnt0 + cnt1 - 1 << '\n';
			else 
				cout << 0 << '\n';
		}
	}	
}

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: 44ms
memory: 5700kb

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

result:

wrong answer 63rd numbers differ - expected: '0', found: '1'