답안 #159412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
159412 2019-10-22T16:02:30 Z iefnah06 구경하기 (JOI13_watching) C++11
100 / 100
108 ms 16252 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 2010;
int N, P, Q;
int A[MAXN];
int dp[MAXN][MAXN];

int nxtSmall[MAXN];
int nxtLarge[MAXN];

bool isGood(int w) {
	for (int i = 0, j = 0; i < N; i++) {
		while (j < N && 0ll + A[i] + w - 1 >= A[j]) j++;
		nxtSmall[i] = j;
	}
	for (int i = 0, j = 0; i < N; i++) {
		while (j < N && 0ll + A[i] + 2*w - 1 >= A[j]) j++;
		nxtLarge[i] = j;
	}

	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	for (int a = 0; a <= P; a++) {
		for (int b = 0; b <= Q; b++) {
			int cur = dp[a][b];
			if (cur == -1) continue;
			if (cur == N) return true;
			dp[a+1][b] = max(dp[a+1][b], nxtSmall[cur]);
			dp[a][b+1] = max(dp[a][b+1], nxtLarge[cur]);
		}
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> P >> Q;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	if (P >= N || Q >= N) {
		cout << 1 << '\n';
		exit(0);
	}

	sort(A, A + N);
	int mi = 0;
	int ma = int(1e9);
	while (ma - mi > 1) {
		int md = (mi + ma) / 2;
		if (isGood(md)) {
			ma = md;
		} else {
			mi = md;
		}
	}
	cout << ma << '\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 16120 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 41 ms 16248 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 44 ms 16200 KB Output is correct
8 Correct 41 ms 16120 KB Output is correct
9 Correct 41 ms 16120 KB Output is correct
10 Correct 41 ms 16120 KB Output is correct
11 Correct 42 ms 16124 KB Output is correct
12 Correct 42 ms 16120 KB Output is correct
13 Correct 45 ms 16240 KB Output is correct
14 Correct 40 ms 16092 KB Output is correct
15 Correct 40 ms 16120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 16212 KB Output is correct
2 Correct 40 ms 16120 KB Output is correct
3 Correct 83 ms 16120 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 380 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 43 ms 16248 KB Output is correct
8 Correct 54 ms 16248 KB Output is correct
9 Correct 52 ms 16248 KB Output is correct
10 Correct 59 ms 16248 KB Output is correct
11 Correct 47 ms 16252 KB Output is correct
12 Correct 108 ms 16248 KB Output is correct
13 Correct 45 ms 16248 KB Output is correct
14 Correct 41 ms 16220 KB Output is correct
15 Correct 43 ms 16248 KB Output is correct