QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#345040#8057. Best Carry Player 4111445#WA 37ms5684kbC++23884b2024-03-06 01:18:202024-03-06 01:18:20

Judging History

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

  • [2024-03-06 01:18:20]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:5684kb
  • [2024-03-06 01:18:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define N 1000000

ll i,j,k,n,t;
ll a[N+50],b[N+50],res,na,nb,sb,mxa,mxb;

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>t;
	while(t--){
		cin>>n; na=nb=0; mxa=mxb=0;
		for(i=0;i<n;i++){
			cin>>a[i]; na+=a[i];
			if(a[i])mxa=max(mxa,i);
		}
		for(i=0;i<n;i++){
			cin>>b[i]; nb+=b[i];
			if(b[i])mxb=max(mxb,i);
		}
		a[0]+=max(0ll,nb-na);
		b[0]+=max(0ll,na-nb);
		res=0; sb=0;
		
		if(mxa+mxb<n){
			cout<<"0\n"; continue;
		}
		
		j=n-1;
		for(i=0;i<n;i++){
			while(j+i>=n-1&&j>=0&&a[i]){
				//cout<<"NMSL "<<i<<' '<<j<<endl;cout<<a[i]<<' '<<b[j]<<' '<<k<<endl;
				
				if(!b[j]){
					j--; continue;
				}
				if(j+i>=n)sb=1;
				k=min(a[i],b[j]);
				
				
				res+=k;
				a[i]-=k;
				b[j]-=k;
			}
		}
		
		if(!sb)res--;
		cout<<res<<'\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5604kb

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: 37ms
memory: 5684kb

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

result:

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