QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#240660#7617. SpectaclexaphoenixTL 1ms7576kbC++141.5kb2023-11-05 17:22:232023-11-05 17:22:24

Judging History

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

  • [2023-11-05 17:22:24]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7576kb
  • [2023-11-05 17:22:23]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<vector>
#define int long long
using namespace std;
int r[1000010],ans[1000010],dif[1000010],n; // dif[i]:r[i] - r[i - 1]
int check(int mid) { //How many pairs we can get with the largest rating difference between 
					 //the chess players in a pair is mid?
	int ans = 0;
	for(int i = 2;i <= n;i++) {
		if(dif[i] > mid) { // can't choose this
			continue;
		} else {
			ans++;
			i++; //skip the next one
		}
	}
	return ans;
}
void Solve(int l,int r1,vector<int> k) {
	if(k.empty()) return;
	//cout << l << " " << r1 << "\n";
	if(l > r1) return;
	int mid = (l + r1) / 2;
	int x = check(mid);
	vector<int> left,right;
	for(auto o:k) {
		if(x >= o) { // mid is an acceptable number
			ans[o] = mid;
			left.push_back(o); // make mid smaller
		} else {
			right.push_back(o); // make mid bigger
		}
	}
	Solve(l,mid - 1,left);
	Solve(mid + 1,r1,right);
}
signed main()
{
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
	cin.tie(0) -> ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1;i <= n;i++) {
		cin >> r[i];
	}
	sort(r + 1,r + n + 1); // We can prove that if r is sorted , then only the (i,i + 1) pair 
						   // will be chosen 
	for(int i = 1;i <= n;i++) {
		dif[i] = r[i] - r[i - 1];
	}
	vector<int> v;
	for(int i = 1;i <= n / 2;i++) {
		v.push_back(i);
	}
	Solve(1,1e18,v);
	for(int i = 1;i <= n / 2;i++) {
		cout << ans[i] << " ";
	}
	cout << "\n";
}

详细

Test #1:

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

input:

6
100 13 20 14 10 105

output:

1 5 6 

result:

ok single line: '1 5 6 '

Test #2:

score: 0
Accepted
time: 0ms
memory: 7576kb

input:

2
1 1000000000000000000

output:

999999999999999999 

result:

ok single line: '999999999999999999 '

Test #3:

score: -100
Time Limit Exceeded

input:

200000
30977570544127554 30977570529630987 30977570554040634 30977570903666181 30977570284338326 30977570675313216 30977569987827221 30977570780807305 30977570623822067 30977570207823010 30977569932624714 30977570440962037 30977570343703869 30977570239637322 30977570141845422 30977570372368100 30977...

output:


result: