# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1052861 | 2024-08-11T04:59:32 Z | manhlinh1501 | Watching (JOI13_watching) | C++17 | 78 ms | 16228 KB |
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int MAXN = 2e3 + 5; const int oo32 = 1e9; int N, P, Q; int a[MAXN]; int dp[MAXN][MAXN]; bool check(int K) { memset(dp, 0x3f, sizeof dp); dp[0][0] = 0; int x = 0, y = 0; for(int i = 1; i <= N; i++) { while(x < i and a[x + 1] < a[i] - K + 1) x++; while(y < i and a[y + 1] < a[i] - 2 * K + 1) y++; for(int j = 0; j <= P; j++) { dp[i][j] = dp[y][j] + 1; if(j > 0) dp[i][j] = min(dp[i][j], dp[x][j - 1]); } } for(int i = 1; i <= P; i++) { if(dp[N][i] <= Q) return true; } return false; } signed main() { #define TASK "code" if (fopen(TASK ".inp", "r")) { freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> P >> Q; for(int i = 1; i <= N; i++) cin >> a[i]; if(P + Q >= N) return cout << 1, 0; P = min(P, N); Q = min(Q, N); sort(a + 1, a + N + 1); int low = 1, high = oo32; int ans = -1; while(low <= high) { int mid = (low + high) / 2; if(check(mid)) { ans = mid; high = mid - 1; } else low = mid + 1; } cout << ans; return (0 ^ 0); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 15964 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 10 ms | 16188 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 10 ms | 16004 KB | Output is correct |
8 | Correct | 10 ms | 16196 KB | Output is correct |
9 | Correct | 10 ms | 15964 KB | Output is correct |
10 | Correct | 10 ms | 15964 KB | Output is correct |
11 | Correct | 9 ms | 16196 KB | Output is correct |
12 | Correct | 10 ms | 16188 KB | Output is correct |
13 | Correct | 11 ms | 16188 KB | Output is correct |
14 | Correct | 9 ms | 15964 KB | Output is correct |
15 | Correct | 9 ms | 16196 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 15964 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 11 ms | 16216 KB | Output is correct |
8 | Correct | 15 ms | 15964 KB | Output is correct |
9 | Correct | 38 ms | 16220 KB | Output is correct |
10 | Correct | 78 ms | 16196 KB | Output is correct |
11 | Correct | 13 ms | 16220 KB | Output is correct |
12 | Correct | 44 ms | 15964 KB | Output is correct |
13 | Correct | 11 ms | 16216 KB | Output is correct |
14 | Correct | 11 ms | 16228 KB | Output is correct |
15 | Correct | 12 ms | 15964 KB | Output is correct |