답안 #765220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765220 2023-06-24T09:29:46 Z yusuf12360 구경하기 (JOI13_watching) C++14
0 / 100
3 ms 340 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int> a;
int n;
int binser(int x) {
	int l=0, r=n-1, ans=0;
	while(l<=r) {
		int mid=(l+r)/2;
		if(a[mid]<x) ans=mid, l=mid+1;
		else r=mid-1;
	}
	return ans;
}
bool can(int w, int p, int q) {
	int idx=0;
	while(idx<n) {
		if(p>1 && q) {
			int BIG=binser(a[idx]+2*w);
			if(BIG==n-1) return 1;
			int SMALL=binser(a[idx]+w);
			if(SMALL==n-1) return 1;
			SMALL=binser(a[SMALL+1]+w);
			if(SMALL==n-1) return 1;
			if(SMALL>BIG) p-=2, idx=SMALL;
			else q--, idx=BIG;
		} else if(p && q) {
			int BIG=binser(a[idx]+2*w), SMALL=binser(a[idx]+w);
			if(BIG==n-1 || SMALL==n-1) return 1;
			if(BIG==SMALL) p--, idx=SMALL;
			else q--, idx=BIG;
		} else if(p) idx=binser(a[idx]+w), p--;
		else if(q) idx=binser(a[idx]+2*w), q--;
		else return 0;
		idx++;
	}
	return 1;
}
signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int p, q; cin >> n >> p >> q;
	a.resize(n);
	for(int &p : a) cin >> p;
	sort(a.begin(), a.end());
	int l=1, r=1e9, w=1e9;
	while(l<=r) {
		int mid=(l+r)/2;
		if(can(mid, p, q)) w=mid, r=mid-1;
		else l=mid+1;
	}
	cout << w << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Incorrect 1 ms 212 KB Output isn't correct
8 Halted 0 ms 0 KB -