# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100811 | 2019-03-14T15:22:52 Z | arman_ferdous | Watching (JOI13_watching) | C++17 | 187 ms | 8576 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2019; int n, p, q, arr[N]; int x[N], y[N], dp[N][N]; bool can(int w) { int cur = 0; for(int i = 0; i < n; i++) { while(cur + 1 < n && arr[cur + 1] - arr[i] + 1 <= w) cur++; x[i] = cur; } cur = 0; for(int i = 0; i < n; i++) { while(cur + 1 < n && arr[cur + 1] - arr[i] + 1 <= 2*w) cur++; y[i] = cur; } for(int i = 0; i <= p; i++) for(int j = 0; j <= q; j++) { dp[i][j] = -1; if(i == 0 && j == 0) continue; if(i != 0) dp[i][j] = max({x[dp[i-1][j] + 1], dp[i-1][j], dp[i][j]}); if(j != 0) dp[i][j] = max({y[dp[i][j-1] + 1], dp[i][j-1], dp[i][j]}); } return dp[p][q] >= n-1; } int main() { scanf("%d %d %d", &n, &p, &q); for(int i = 0; i < n; i++) scanf("%d", &arr[i]); sort(arr,arr+n); if(p + q >= n) { puts("1"); return 0; } int lo = 1, hi = (int)1e9+10, ans; while(lo <= hi) { int mid = (lo + hi) >> 1; if(can(mid)) hi = mid-1, ans = mid; else lo = mid+1; } printf("%d", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 2 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 256 KB | Output is correct |
6 | Correct | 2 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 360 KB | Output is correct |
8 | Correct | 2 ms | 384 KB | Output is correct |
9 | Correct | 3 ms | 384 KB | Output is correct |
10 | Correct | 3 ms | 384 KB | Output is correct |
11 | Correct | 2 ms | 512 KB | Output is correct |
12 | Correct | 4 ms | 512 KB | Output is correct |
13 | Correct | 2 ms | 384 KB | Output is correct |
14 | Correct | 2 ms | 384 KB | Output is correct |
15 | Correct | 3 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 384 KB | Output is correct |
4 | Correct | 3 ms | 384 KB | Output is correct |
5 | Correct | 2 ms | 384 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
7 | Correct | 3 ms | 384 KB | Output is correct |
8 | Correct | 21 ms | 1288 KB | Output is correct |
9 | Correct | 23 ms | 3840 KB | Output is correct |
10 | Correct | 41 ms | 8576 KB | Output is correct |
11 | Correct | 38 ms | 1152 KB | Output is correct |
12 | Correct | 187 ms | 8064 KB | Output is correct |
13 | Correct | 4 ms | 356 KB | Output is correct |
14 | Correct | 3 ms | 512 KB | Output is correct |
15 | Correct | 4 ms | 512 KB | Output is correct |