QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#330230#8057. Best Carry Player 4ucup-team2279#WA 40ms3956kbC++201.3kb2024-02-17 13:51:072024-02-17 13:51:07

Judging History

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

  • [2024-02-17 13:51:07]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:3956kb
  • [2024-02-17 13:51:07]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mk make_pair
#define lowbit(x) (x&(-x))
#define pb emplace_back
#define pr pair<int,int>
#define let const auto
#define all(A) A.begin(),A.end()
const int N=5e5+5;
int read(){
	int x=0,f=1; char c=getchar();
	while(('0'>c||c>'9')&&c!='-') c=getchar();
	if(c=='-') f=0,c=getchar();
	while('0'<=c&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f?x:-x;
}
void solve(){
	int m=read();
	vector <int> a(m),b(m);
	for(auto &o:a) o=read();
	for(auto &o:b) o=read();
	int posa=0,posb=m-1;
	ll ans=0,ans2=0;
	ll sa=accumulate(all(a),0ll),sb=accumulate(all(b),0ll);
	if(sa<sb) a[0]+=sb-sa;
	else b[0]+=sa-sb;
	int lasa=m-1,lasb=m-1;
	while(lasa>0&&!a[lasa]) lasa--;
	while(lasb>0&&!b[lasb]) lasb--;
	if(lasa+lasb<m) return puts("0"),void();
	int p=-1,yes=0;
	while(posa<m&&posb>=0){
		int cur=min(a[posa],b[posb]);
		if(posa+posb>=m) ans+=cur;
		else if(posa+posb==m-1) ans2+=cur;
		else{
			posa++;
			continue;
		}
		if(cur>0&&p==-1) p=posa;
		a[posa]-=cur,b[posb]-=cur;
		if(!a[posa]) posa++;
		if(!b[posb]) posb--;
	}
	if(~p&&p<m-1&&*max_element(a.begin()+p+1,a.end())>0) yes=1;
	if(ans) yes=1;
	printf("%lld\n",ans+ans2-(!yes));
}
int main(){
	int T=read();
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 18ms
memory: 3700kb

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

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 9ms
memory: 3656kb

input:

1000
500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

0
1
1
2
2
2
0
0
0
3
1
1
2
0
1
0
1
1
3
0
0
4
3
1
4
4
0
0
2
1
3
3
0
0
1
0
1
1
0
0
2
1
2
0
3
1
3
1
3
4
2
1
1
2
3
0
0
1
2
0
0
1
1
1
1
2
1
2
2
0
2
2
1
1
3
0
0
1
2
0
1
3
0
0
1
1
0
0
1
0
3
1
2
0
0
5
1
1
1
3
1
4
1
0
0
0
0
0
1
3
1
2
1
0
0
0
0
0
1
1
0
4
0
1
1
3
0
1
0
0
2
3
0
1
2
1
1
1
0
3
0
0
3
2
1
1
0
1
0
1
...

result:

ok 1000 numbers

Test #4:

score: -100
Wrong Answer
time: 40ms
memory: 3956kb

input:

100000
5
119777838 337555280 806504015 458289944 321614229
979242871 431783189 423329635 193632121 7339369
5
189264782 667669243 753322761 861814678 224007583
977519325 104432095 940220826 712094722 903574615
5
977791540 278658984 601762324 633391706 36807634
689562032 997406456 118939957 891425821 ...

output:

1377698543
2884329841
1699584169
2132012702
2531472710
2754014935
2585135038
2577893498
2034726862
2303377730
1476887044
2618960687
1626312268
1068946376
600795101
927483202
2151016849
2256729729
2291627593
1751199962
2412405837
1884010446
2553701265
2014856631
848686688
1069641213
2412585811
167144...

result:

wrong answer 39th numbers differ - expected: '1572566306', found: '-1412970174'