답안 #159411

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
159411 2019-10-22T15:53:09 Z iefnah06 구경하기 (JOI13_watching) C++11
100 / 100
114 ms 16276 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 45 ms 16120 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 44 ms 16120 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 42 ms 16120 KB Output is correct
8 Correct 41 ms 16120 KB Output is correct
9 Correct 39 ms 16120 KB Output is correct
10 Correct 41 ms 16120 KB Output is correct
11 Correct 44 ms 16120 KB Output is correct
12 Correct 43 ms 16248 KB Output is correct
13 Correct 50 ms 16208 KB Output is correct
14 Correct 43 ms 16120 KB Output is correct
15 Correct 79 ms 16200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 16120 KB Output is correct
2 Correct 41 ms 16240 KB Output is correct
3 Correct 72 ms 16272 KB Output is correct
4 Correct 2 ms 376 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 16248 KB Output is correct
8 Correct 53 ms 16248 KB Output is correct
9 Correct 53 ms 16276 KB Output is correct
10 Correct 63 ms 16120 KB Output is correct
11 Correct 47 ms 16236 KB Output is correct
12 Correct 114 ms 16248 KB Output is correct
13 Correct 44 ms 16120 KB Output is correct
14 Correct 44 ms 16120 KB Output is correct
15 Correct 44 ms 16248 KB Output is correct