# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
379349 | 2021-03-18T02:33:16 Z | pavement | Watching (JOI13_watching) | C++17 | 1000 ms | 16256 KB |
#include <bits/stdc++.h> using namespace std; int a[2005], dp[2005][2005]; int main() { int n, p, q; scanf("%d%d%d", &n, &p, &q); q = min(q, n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); int lo = 1, hi = a[n - 1] - a[0] + 1, ans = -1; while (lo <= hi) { int mid = (lo + hi) / 2; dp[0][0] = 1; for (int i = 1; i <= q; i++) dp[0][i] = 0; for (int i = 1; i < n; i++) { for (int j = 0; j <= q; j++) { int dpp = lower_bound(a, a + i + 1, a[i] - mid + 1) - a - 1, dpq = lower_bound(a, a + i + 1, a[i] - 2 * mid + 1) - a - 1; if (dpq < 0 && j) dp[i][j] = 0; else if (dpp < 0) dp[i][j] = 1; else if (j) dp[i][j] = min(dp[dpp][j] + 1, dp[dpq][j - 1]); else dp[i][j] = dp[dpp][0] + 1; } } if (dp[n - 1][q] <= p) ans = mid, hi = mid - 1; else lo = mid + 1; } printf("%d\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 748 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 2 ms | 748 KB | Output is correct |
5 | Correct | 5 ms | 748 KB | Output is correct |
6 | Correct | 5 ms | 748 KB | Output is correct |
7 | Correct | 1 ms | 748 KB | Output is correct |
8 | Correct | 2 ms | 748 KB | Output is correct |
9 | Correct | 1 ms | 748 KB | Output is correct |
10 | Correct | 5 ms | 748 KB | Output is correct |
11 | Correct | 2 ms | 748 KB | Output is correct |
12 | Correct | 3 ms | 748 KB | Output is correct |
13 | Correct | 1 ms | 748 KB | Output is correct |
14 | Correct | 1 ms | 748 KB | Output is correct |
15 | Correct | 1 ms | 748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 8428 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Execution timed out | 1091 ms | 16256 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |