#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
const int MAXN = 2e3 + 10;
// dp[i][j] stores maximum number of small cameras left given j large left and all up to i inclusive is taken
int dp[MAXN][MAXN];
int x[MAXN];
int N, P, Q;
set<pi> loc;
bool possible(int w) {
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= Q; j++) {
dp[i][j] = -1;
}
}
dp[0][0] = P;
for (pi cLoc : loc) {
int i = cLoc.s;
if(i==0) continue;
for (int nL = 0; nL <= Q; nL++) {
// case 1: use large
if (nL > 0) {
int pI = prev(loc.lower_bound({x[i] - 2 * w + 1, -1}))->s;
dp[i][nL] = max(dp[i][nL], dp[pI][nL - 1]);
}
// case 2: use small
int pI = prev(loc.lower_bound({x[i] - w + 1, -1}))->s;
dp[i][nL] = max(dp[i][nL], dp[pI][nL] - 1);
}
}
int lastI = prev(loc.end())->s;
for (int nL = 0; nL <= Q; nL++) {
if (dp[lastI][nL] >= 0) {
return true;
}
}
return false;
}
int binSearch() {
int low = 1;
int hi = 1e9;
while (low != hi) {
assert(low < hi);
int mid = (low + hi) / 2;
if (possible(mid)) {
assert(hi != mid);
hi = mid;
} else {
low = mid + 1;
}
}
return low;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> P >> Q;
P = min(P, N);
Q = min(Q, N);
x[0] = -2e9;
loc.insert({x[0], 0});
for (int i = 1; i <= N; i++) {
cin >> x[i];
loc.insert({x[i], i});
}
// cout << possible(9) << endl;
int ans = binSearch();
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
5 ms |
256 KB |
Output is correct |
4 |
Correct |
6 ms |
640 KB |
Output is correct |
5 |
Correct |
15 ms |
768 KB |
Output is correct |
6 |
Correct |
15 ms |
768 KB |
Output is correct |
7 |
Correct |
5 ms |
768 KB |
Output is correct |
8 |
Correct |
6 ms |
768 KB |
Output is correct |
9 |
Correct |
6 ms |
768 KB |
Output is correct |
10 |
Correct |
11 ms |
768 KB |
Output is correct |
11 |
Correct |
6 ms |
768 KB |
Output is correct |
12 |
Correct |
10 ms |
768 KB |
Output is correct |
13 |
Correct |
6 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
768 KB |
Output is correct |
15 |
Correct |
6 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
8448 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Execution timed out |
1099 ms |
16256 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |