QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#90912#1299. Jinxed BettinghippotumuxWA 3ms3488kbC++141.0kb2023-03-26 02:40:102023-03-26 02:40:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-26 02:40:13]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3488kb
  • [2023-03-26 02:40:10]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define inf int(1e8)
#define lnf ll(1e18)
#define pair<int,int> pii;
#define fastio ios::sync_with_stdio(false),cin.tie(0)
using namespace std;
vector<ll> vec;
ll n, tar;

int SUM (ll target) {
	ll sum = 0;
	for (auto it : vec) {
		if (tar < it + target) sum += it + target - tar;
		if (sum > target) return 0;
	}
	if (sum == target) return 2;
	return 1;
}

void solve(){
	
	cin >> n;
	cin >> tar;
	vec.resize(n-1);
	int times = 0;
	for (int i = 0 ; i < n - 1; i++) cin >> vec[i];
	for (auto it : vec) {
		if (it == tar) times ++;
	}
	if (times >= 2) {
		cout << 0 << '\n';
		return;
	}
	ll l = 1, r = 1e17;
	while (l < r) {
		ll mid = (l + r + 1)/2;
		if (SUM(mid)) l = mid;
		else r = mid - 1;
	}
	ll mid = (l + r)/2;
	ll ans;
	ll k = 1;
	for (ll i = max(k,mid - 10); i <= mid + 10 ; i++) {
		if (SUM(i) == 2){
			cout << i << '\n';
			return ;
		}else if(SUM(i) == 1){
			ans = i;
		}else break;
	}
	cout << ans << '\n';
}

int main(void) {
	fastio;
	solve();		
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 3376kb

input:

3
23 23 23

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3488kb

input:

3
9999999999999997 99999977 42

output:

19999999899999975

result:

ok single line: '19999999899999975'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3356kb

input:

5
10 3 3 3 3

output:

9

result:

wrong answer 1st lines differ - expected: '10', found: '9'