Submission #159416

# Submission time Handle Problem Language Result Execution time Memory
159416 2019-10-22T16:04:47 Z iefnah06 Watching (JOI13_watching) C++11
100 / 100
206 ms 16376 KB
#include<bits/stdc++.h>
using namespace std;

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

int dp[MAXN][MAXN];
int nxtLarge[MAXN];
int nxtSmall[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, 0, sizeof(dp));
	for (int a = 0; a <= P; a++) {
		for (int b = 0; b <= Q; b++) {
			int cur = dp[a][b];
			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::sync_with_stdio(0), cin.tie(0);
	cin >> N >> P >> Q;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	if (P >= N || Q >= N) {
		cout << 1 << '\n';
		exit(0);
	}

	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;
}
# Verdict Execution time Memory Grader output
1 Correct 43 ms 16120 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 43 ms 16092 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 45 ms 16092 KB Output is correct
8 Correct 41 ms 16120 KB Output is correct
9 Correct 41 ms 16184 KB Output is correct
10 Correct 43 ms 16120 KB Output is correct
11 Correct 51 ms 16204 KB Output is correct
12 Correct 43 ms 16120 KB Output is correct
13 Correct 42 ms 16120 KB Output is correct
14 Correct 206 ms 16092 KB Output is correct
15 Correct 56 ms 16376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 16160 KB Output is correct
2 Correct 54 ms 16120 KB Output is correct
3 Correct 60 ms 16212 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 53 ms 16120 KB Output is correct
8 Correct 61 ms 16220 KB Output is correct
9 Correct 49 ms 16248 KB Output is correct
10 Correct 54 ms 16248 KB Output is correct
11 Correct 50 ms 16216 KB Output is correct
12 Correct 91 ms 16128 KB Output is correct
13 Correct 64 ms 16076 KB Output is correct
14 Correct 41 ms 16236 KB Output is correct
15 Correct 43 ms 16240 KB Output is correct