#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <bits/stdc++.h>
#include <memory.h>
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef long double llf;
typedef unsigned int uint;
using namespace std;
const int N_ = 2005;
int N, P, Q, A[N_];
int res;
int Table[N_][N_];
int X[N_], Y[N_];
bool possible (int w) {
for(int i = 1, j = 1; i <= N; i++) {
while(A[j] - A[i] < w && j <= N) ++j;
X[i] = --j;
}
for(int i = 1, j = 1; i <= N; i++) {
while(A[j] - A[i] < w+w && j <= N) ++j;
Y[i] = --j;
}
X[N+1] = Y[N+1] = N;
for(int i = 0; i <= P; i++) {
for(int j = 0; j <= Q; j++) Table[i][j] = 0;
}
for(int i = 0; i <= P; i++) {
for(int j = 0; j <= Q; j++) {
if(i < P) Table[i+1][j] = max(Table[i+1][j], X[Table[i][j] + 1]);
if(j < Q) Table[i][j+1] = max(Table[i][j+1], Y[Table[i][j] + 1]);
}
}
return Table[P][Q] >= N;
}
int main() {
scanf("%d%d%d", &N, &P, &Q);
if(P + Q >= N) {
puts("1");
return 0;
}
for(int i = 1; i <= N; i++) scanf("%d", A+i);
sort(A+1, A+N+1);
N = unique(A+1, A+N+1) - (A+1);
int low = 0, high = (int)1e9;
while(low <= high) {
int mid = (low + high) >> 1;
if(possible(mid)) {
res = mid;
high = mid - 1;
}else {
low = mid + 1;
}
}
printf("%d\n", res);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
17404 KB |
Output is correct |
2 |
Correct |
0 ms |
17404 KB |
Output is correct |
3 |
Correct |
0 ms |
17404 KB |
Output is correct |
4 |
Correct |
0 ms |
17404 KB |
Output is correct |
5 |
Correct |
0 ms |
17404 KB |
Output is correct |
6 |
Correct |
0 ms |
17404 KB |
Output is correct |
7 |
Correct |
0 ms |
17404 KB |
Output is correct |
8 |
Correct |
0 ms |
17404 KB |
Output is correct |
9 |
Correct |
0 ms |
17404 KB |
Output is correct |
10 |
Correct |
0 ms |
17404 KB |
Output is correct |
11 |
Correct |
0 ms |
17404 KB |
Output is correct |
12 |
Correct |
0 ms |
17404 KB |
Output is correct |
13 |
Correct |
0 ms |
17404 KB |
Output is correct |
14 |
Correct |
0 ms |
17404 KB |
Output is correct |
15 |
Correct |
0 ms |
17404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
17404 KB |
Output is correct |
2 |
Correct |
0 ms |
17404 KB |
Output is correct |
3 |
Correct |
0 ms |
17404 KB |
Output is correct |
4 |
Correct |
0 ms |
17404 KB |
Output is correct |
5 |
Correct |
0 ms |
17404 KB |
Output is correct |
6 |
Correct |
0 ms |
17404 KB |
Output is correct |
7 |
Correct |
0 ms |
17404 KB |
Output is correct |
8 |
Correct |
32 ms |
17404 KB |
Output is correct |
9 |
Correct |
32 ms |
17404 KB |
Output is correct |
10 |
Correct |
52 ms |
17404 KB |
Output is correct |
11 |
Correct |
56 ms |
17404 KB |
Output is correct |
12 |
Correct |
328 ms |
17404 KB |
Output is correct |
13 |
Correct |
0 ms |
17404 KB |
Output is correct |
14 |
Correct |
0 ms |
17404 KB |
Output is correct |
15 |
Correct |
0 ms |
17404 KB |
Output is correct |