#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> events;
vector <vector <vector <bool>>> dp;
vector <vector <vector <int>>> ready;
bool solve(int i, int p, int q, int w) {
if (i >= n)
return true;
if (ready[i][p][q] == w)
return dp[i][p][q];
bool ans = false;
if (p >= 1) {
int it = upper_bound(events.begin(), events.end(), events[i] + w - 1) - events.begin();
ans |= solve(it, p-1, q, w);
}
if (q >= 1) {
int it = upper_bound(events.begin(), events.end(), events[i] + 2*w - 1) - events.begin();
ans |= solve(it, p, q-1, w);
}
ready[i][p][q] = w;
dp[i][p][q] = ans;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int p, q;
cin >> n >> p >> q;
events = vector <int> (n);
for (int i = 0; i < n; i++)
cin >> events[i];
sort(events.begin(), events.end());
if (p + q >= n) {
cout << 1 << '\n';
return 0;
}
dp = vector <vector <vector <bool>>> (n, vector <vector <bool>> (p+1, vector <bool> (q+1)));
ready = vector <vector <vector <int>>> (n, vector <vector <int>> (p+1, vector <int> (q+1)));
int lo = 1, hi = 1e9;
while (lo < hi) {
int mid = lo + (hi - lo) / 2;
if (solve(0, p, q, mid))
hi = mid;
else
lo = mid + 1;
}
cout << lo << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
428 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
4 ms |
860 KB |
Output is correct |
11 |
Correct |
4 ms |
1372 KB |
Output is correct |
12 |
Correct |
6 ms |
2220 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
992 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
484 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
5724 KB |
Output is correct |
8 |
Runtime error |
137 ms |
262144 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |