Submission #100874

# Submission time Handle Problem Language Result Execution time Memory
100874 2019-03-15T01:19:40 Z E869120 Watching (JOI13_watching) C++14
100 / 100
197 ms 8716 KB
#include <bits/stdc++.h>
using namespace std;

long long N, A[2009]; int P, Q;
int dp[2009][2009];
int P1[2009], P2[2009];

bool solve(long long uplim) {
	for (int i = 0; i <= N; i++) P1[i] = lower_bound(A, A + N, A[i] + uplim) - A;
	for (int i = 0; i <= N; i++) P2[i] = lower_bound(A, A + N, A[i] + 2LL * uplim) - A;
	
	for (int i = 0; i <= P; i++) { for (int j = 0; j <= Q; j++) dp[i][j] = 0; }
	
	for (int i = 0; i <= P; i++) {
		for (int j = 0; j <= Q; j++) {
			dp[i][j + 1] = max(dp[i][j + 1], P2[dp[i][j]]);
			dp[i + 1][j] = max(dp[i + 1][j], P1[dp[i][j]]);
		}
	}
	if (dp[P][Q] == N) return true;
	return false;
}

int main(){
	cin >> N >> P >> Q; if (Q >= N) Q = N; if (P + Q >= N) P = N - Q;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A, A + N);
	A[N] = 1000000007;
	
	long long L = 1, R = 1000000007, M, maxn = (1 << 30);
	for (int i = 0; i < 35; i++) {
		M = (L + R) / 2;
		bool ok = solve(M);
		if (ok == true) { R = M; maxn = min(maxn, M); }
		else { L = M; }
	}
	cout << maxn << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 640 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 3 ms 640 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 167 ms 4352 KB Output is correct
4 Correct 47 ms 8716 KB Output is correct
5 Correct 10 ms 552 KB Output is correct
6 Correct 10 ms 384 KB Output is correct
7 Correct 9 ms 512 KB Output is correct
8 Correct 26 ms 1280 KB Output is correct
9 Correct 29 ms 3712 KB Output is correct
10 Correct 53 ms 8704 KB Output is correct
11 Correct 40 ms 1024 KB Output is correct
12 Correct 197 ms 8160 KB Output is correct
13 Correct 9 ms 384 KB Output is correct
14 Correct 10 ms 512 KB Output is correct
15 Correct 10 ms 512 KB Output is correct