QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#329910#8057. Best Carry Player 4ucup-team266#WA 44ms3652kbC++201.4kb2024-02-17 08:18:012024-02-17 08:18:02

Judging History

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

  • [2024-02-17 08:18:02]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:3652kb
  • [2024-02-17 08:18:01]
  • 提交

answer

/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
 
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts 
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest

9. module on time 
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pii pair<long long,long long>
#define mp make_pair
#define pb push_back
const int mod=998244353;
const int inf=0x3f3f3f3f;
const int INF=1e18;
int n;
int a[200005],b[200005];
void solve()
{
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	a[0]=b[0]=inf; 
	int ans=0;
	for(int i=n-1,flg=0,j=0;i>=0;i--) if(a[i])
	{
		if(!flg)
		{
			for(int l=0;l<n;l++) if(b[l]&&l+i>=n)
			{
				ans++,b[l]--,a[i]--,flg=1;
				break;
			}
			if(!flg)
			{
				cout<<"0\n";
				return;
			}
		}
		j=max(j,n-1-i);
		while(j<n)
		{
			int d=min(a[i],b[j]);
			ans+=d;
			if(d) a[i]-=d,b[j]-=d;
			if(!b[j]) j++;
			if(!a[i]) break;
		}
	}
	cout<<ans<<"\n";
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int _=1;
	cin>>_;
	while(_--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

result:

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