QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#545995#8057. Best Carry Player 4FluoresceWA 1ms7720kbC++201.8kb2024-09-03 18:44:322024-09-03 18:44:33

Judging History

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

  • [2024-09-03 18:44:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7720kb
  • [2024-09-03 18:44:32]
  • 提交

answer

#include<bits/stdc++.h>
#include<unordered_map>
typedef long long ll;
typedef long double ld;
#define debug(a) cout<<a<<'\n'
#define Pll pair<ll,ll>
#define PII pair<int,int>
#define ft first
#define sd second
#define pushk push_back
#define popk pop_back
#define vec vector
using namespace std;
const int N = 5e5 + 10, M = 1e7, mod = 998244353;
const ll inf = 1e18;
const ld eps = 1e-8;
int mov[4][2] = { {0,1},{1,0},{-1,0},{0,-1} }, dx, dy;
void bout(bool f) {
    if (f)cout << "YES\n";
    else cout << "NO\n";
}
ll n, m, k;
ll s1[N],s2[N],a[N],b[N]; 

void solve() {
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
		s1[0]+=a[i];
	}
	for(int i=0;i<n;++i){
		cin>>b[i];
		s2[0]+=b[i];
	}
	s1[0]=a[0]+max(s1[0],s2[0])-s1[0];
	s2[0]=b[0]+max(s1[0],s2[0])-s2[0];	
	for(int i=1;i<n;++i){
		s1[i]=s1[i-1]+a[i];
		s2[i]=s2[i-1]+b[i];
	}
	bool f=0;
	int l=0,r=n-1;
	ll ans=0,res;
	while(l<=n-1){
		while(a[l]&&l+r>=n-1){
			if(!b[r])--r;
			else{
				if(l+r>=n)f=1;
				res=min(a[l],b[r]);
				ans+=res;
				a[l]-=res;
				b[r]-=res;					
			}
		}
		++l;
	}
	for(int i=0;i<n;++i){
		if(a[i]&&s2[n-1]-s2[n-1-i])f=1;
		if(b[i]&&s1[n-1]-s1[n-1-i])f=1;
	}
	if(f)cout<<ans<<'\n';
	else{
		for(int i=n-1;i>=(n+1)/2;--i){
			if(s1[n-1]-s1[i-1]>1&&s2[n-1]-s2[i-1]>1)f=1;
		}
		if(f)cout<<max((ll)0,ans-1)<<'\n';
		else cout<<0<<'\n';
	}
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    streambuf* cinbackup = cin.rdbuf(), * coubackup = cout.rdbuf();
    ifstream fin("in.txt");
    ofstream fout("out.txt");
    cin.rdbuf(fin.rdbuf());
    cout.rdbuf(fout.rdbuf());
#endif
    int _ = 1, __ = 1;
    cin >> _;
    __ = _;
    while (_--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7720kb

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:

3
1
2
467900
29

result:

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