QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#739399#8057. Best Carry Player 4UESTC_NLNS#WA 58ms9752kbC++202.7kb2024-11-12 21:40:182024-11-12 21:40:18

Judging History

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

  • [2024-11-12 21:40:18]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:9752kb
  • [2024-11-12 21:40:18]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5e5+5,INF=0x3f3f3f3f;
int T,n,s1,s2,p,tmp;
ll ans,ans1,ans2,sa,sb,a[N],b[N],aa[N],bb[N];
set<int> s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n;s.clear();p=INF;sa=sb=0;
		for(int i=0;i<n;i++) cin>>a[i],sa+=a[i];
		for(int i=0;i<n;i++) cin>>b[i],sb+=b[i];
		if(sa>sb) b[0]+=sa-sb;
		else a[0]+=sb-sa;
		for(int i=0;i<n;i++) if(b[i]) s.insert(i);
		for(int i=n-1;i>=1;i--)
		{
			if(!a[i]) continue;
			auto it=s.lower_bound(n-i);
			if(it==s.end()) continue;
			tmp=(i+(*it))-n;
			if(tmp<p) p=tmp,s1=i,s2=*it;
		}
		if(p==INF)
		{
			cout<<"0\n";
			continue;
		}
		ans1=1;
		for(int i=0;i<n;i++) aa[i]=a[i],bb[i]=b[i];
		aa[s1]--;bb[s2]--;
		for(int i=0,j=n-1;;)
		{
			while(j>=0&&!bb[j]) j--;
			if(j==-1) break;
			while(i<n&&(i+j<n-1||(!aa[i]))) i++;
			if(i==n) break;
			tmp=min(aa[i],bb[j]);
			aa[i]-=tmp;
			bb[j]-=tmp;
			ans1+=tmp;
		}
		ans=ans1;
		p=INF;
		for(int i=1;i<n;i++)
		{
			if(!a[i]) continue;
			auto it=s.lower_bound(n-i);
			if(it==s.end()) continue;
			tmp=(i+(*it))-n;
			if(tmp<p) p=tmp,s1=i,s2=*it;
		}
		ans1=1;
		for(int i=0;i<n;i++) aa[i]=a[i],bb[i]=b[i];
		aa[s1]--;bb[s2]--;
		for(int i=0,j=n-1;;)
		{
			while(j>=0&&!bb[j]) j--;
			if(j==-1) break;
			while(i<n&&(i+j<n-1||(!aa[i]))) i++;
			if(i==n) break;
			tmp=min(aa[i],bb[j]);
			aa[i]-=tmp;
			bb[j]-=tmp;
			ans1+=tmp;
		}
		ans=max(ans,ans1);
		for(int i=n-1;i>=1;i--)
		{
			if(!a[i]) continue;
			auto it=s.lower_bound(n-i);
			if(it==s.end()) continue;
			s1=i;s2=*it;break;
		}
		ans1=1;
		for(int i=0;i<n;i++) aa[i]=a[i],bb[i]=b[i];
		aa[s1]--;bb[s2]--;
		for(int i=0,j=n-1;;)
		{
			while(j>=0&&!bb[j]) j--;
			if(j==-1) break;
			while(i<n&&(i+j<n-1||(!aa[i]))) i++;
			if(i==n) break;
			tmp=min(aa[i],bb[j]);
			aa[i]-=tmp;
			bb[j]-=tmp;
			ans1+=tmp;
		}
		ans=max(ans,ans1);
		for(int i=1;i<n;i++)
		{
			if(!a[i]) continue;
			auto it=s.lower_bound(n-i);
			if(it==s.end()) continue;
			s1=i;s2=*it;break;
		}
		ans1=1;
		for(int i=0;i<n;i++) aa[i]=a[i],bb[i]=b[i];
		aa[s1]--;bb[s2]--;
		for(int i=0,j=n-1;;)
		{
			while(j>=0&&!bb[j]) j--;
			if(j==-1) break;
			while(i<n&&(i+j<n-1||(!aa[i]))) i++;
			if(i==n) break;
			tmp=min(aa[i],bb[j]);
			aa[i]-=tmp;
			bb[j]-=tmp;
			ans1+=tmp;
		}
		ans=max(ans,ans1);
		cout<<ans<<"\n";
	}
	return 0;
}
/*
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

1
10
5 3 5 3 2 4 2 4 1 5
9 9 8 2 4 4 3 5 3 0
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 58ms
memory: 9752kb

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:

wrong answer 8580th numbers differ - expected: '5', found: '4'