QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625754#8057. Best Carry Player 4tjf4WA 2ms11772kbC++201.4kb2024-10-09 20:51:012024-10-09 20:51:03

Judging History

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

  • [2024-10-09 20:51:03]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11772kb
  • [2024-10-09 20:51:01]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<char> vc;
const ll inf=1e18;
const int N=5e5+10;
ll m,a[N],b[N],c[N],as[N],bs[N];
int main() {
	IOS
	int T;
	cin>>T;
	while(T--) {
		cin>>m; c[m]=0;
		ll s1=0,s2=0;
		for(int i=0;i<=m+1;i++) a[i]=b[i]=c[i]=as[i]=bs[i]=0;
		for(int i=0;i<m;i++) cin>>a[i],s1+=a[i],as[i]=a[i];
		for(int i=0;i<m;i++) cin>>b[i],s2+=b[i],bs[i]=b[i];
		if(s1>s2) b[0]+=abs(s1-s2),bs[0]=b[0];
		else a[0]+=abs(s1-s2),as[0]=a[0];
		ll rf=m-1,sum=0,pd=0;
		for(int i=0;i<m;i++) {
			if(rf<0) break;
			if(a[i]>0&&b[rf]>0&&i+rf>=m) pd=1;
			if(a[i]==b[rf]) {
				sum+=a[i];
				a[i]=b[rf]=0;
				rf--;
			}
			else if(a[i]>b[rf]) {
				sum+=b[rf];
				a[i]-=b[rf];
				b[rf]=0;
				rf--;
				if(i+rf<m-1) {
					if(sum) pd=1;
				}
				else i--;
			}
			else if(a[i]<b[rf]) {
				sum+=a[i];
				b[rf]-=a[i];
			}
		}
		for(int i=0;i<m;i++) a[i]=as[i];
		for(int i=0;i<m;i++) b[i]=bs[i];
		if(pd) cout<<sum<<'\n';
		else {
			ll mx1=-1,mx2=-1;
			for(int i=m-1;i>=0;i--) {
				if(a[i]>0&&mx1<0) mx1=i;
				if(b[i]>0&&mx2<0) mx2=i;
			}
			if(mx1>=0&&mx2>=0&&mx1+mx2>=m) cout<<sum-1<<'\n';
			else cout<<0<<'\n';
		}
	}
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 11772kb

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:

6
1
2
467900
29

result:

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