QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#625422#8057. Best Carry Player 4tjf4#WA 48ms11864kbC++201.5kb2024-10-09 19:12:552024-10-09 19:12:56

Judging History

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

  • [2024-10-09 19:12:56]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:11864kb
  • [2024-10-09 19:12:55]
  • 提交

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;
		for(int i=0;i<=m+1;i++) a[i]=b[i]=c[i]=as[i]=bs[i]=0;
		ll s1=0,s2=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);
		else a[0]+=abs(s1-s2);
//		for(int i=0;i<m;i++) swap(a[i],b[i]),swap(as[i],bs[i]);
		ll rf=m-1,sum=0,pd=0,fg=0;
		for(int i=0;i<m;i++) {
			ll let=sum;
//			cout<<i<<' '<<rf<<' ';
			if(rf<0) break;
			if(a[i]>0&&b[rf]>0&&i+rf>=m) pd=1;
			if(a[i]>0&&b[i]>0) fg++;
			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);
				else i--;
			}
			else if(a[i]<b[rf]) {
				sum+=a[i];
				b[rf]-=a[i];
			}
//			cout<<sum-let<<'\n';
		}
		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 if(fg>1) cout<<sum-1<<'\n';
		else {
			pd=0;
			for(int i=m-1;i>=0;i--) c[i]=c[i+1]+a[i];
			for(int i=1;i<m;i++) {
				if(c[m-i]&&b[i]) pd=1;
			}
			if(pd==1) cout<<sum-1<<'\n';
			else cout<<0<<'\n';
		}
	}
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 11828kb

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: 48ms
memory: 11864kb

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
-1
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'