QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#545975#8057. Best Carry Player 4FluoresceWA 36ms9748kbC++201.7kb2024-09-03 18:35:552024-09-03 18:35:56

Judging History

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

  • [2024-09-03 18:35:56]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:9748kb
  • [2024-09-03 18:35:55]
  • 提交

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];
	}
	for(int i=0;i<n;++i){
		cin>>b[i];
	}
	s1[0]=s2[0]=a[0]=b[0]=1e9+10;
	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;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 9744kb

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: 36ms
memory: 9748kb

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

result:

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