답안 #468556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468556 2021-08-28T17:22:34 Z mychecksedad 구경하기 (JOI13_watching) C++17
100 / 100
319 ms 16060 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 2010, MX = 1e9;

int n, p, q, arr[N], dp[N][N], go[N][2]; // min_q, max_pos_p, max_pos_j
bool check(int w){
	int a = 1, b = 1;
	for(int i = 1; i <= n; i++){
		while(a < i && arr[a] + w <= arr[i]) a++;
		while(b < i && arr[b] + 2*w <= arr[i]) b++;
		go[i][0] = a - 1, go[i][1] = b - 1;
	}
	int res = MX;
	for(int i = 0; i <= p; i++) dp[0][i] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= p; j++){
			dp[i][j] = MX;
			if(j>0) dp[i][j] = min(dp[i][j], dp[go[i][0]][j - 1]);	
			dp[i][j] = min(dp[i][j], dp[go[i][1]][j] + 1);	
			if(i==n) res = min(res, dp[i][j]);	
			// cout << dp[i][j] << ' ';
		}
		// cout << '\n';
	}
	return (res <= q); 
}


int main(){
	cin >> n >> p >> q;
	for(int i = 1; i <= n; i++) cin >> arr[i];
	if(p + q >= n){
		cout << 1;
		return 0;
	}
	sort(arr+1, arr+n+1);
	int l = 1, h = MX, ans = MX;
	while(l <= h){
		int mid = ((l+h)>>1);
		if(check(mid)){
			ans = min(ans, mid);
			h = mid - 1;
		}else
			l = mid + 1;
	}
	cout << ans;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 716 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 1 ms 716 KB Output is correct
11 Correct 1 ms 716 KB Output is correct
12 Correct 1 ms 716 KB Output is correct
13 Correct 1 ms 716 KB Output is correct
14 Correct 1 ms 716 KB Output is correct
15 Correct 1 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8348 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 8 ms 8396 KB Output is correct
8 Correct 27 ms 9292 KB Output is correct
9 Correct 135 ms 14156 KB Output is correct
10 Correct 319 ms 16060 KB Output is correct
11 Correct 27 ms 9024 KB Output is correct
12 Correct 176 ms 15988 KB Output is correct
13 Correct 8 ms 8560 KB Output is correct
14 Correct 9 ms 8396 KB Output is correct
15 Correct 8 ms 8420 KB Output is correct