# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
553645 | 2022-04-26T12:56:37 Z | QwertyPi | Watching (JOI13_watching) | C++14 | 1000 ms | 15956 KB |
#include <bits/stdc++.h> #define N 2001 using namespace std; int dp[N][N]; int n, p, q; vector<int> a; bool ok(int w){ for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = (1 << 30); dp[0][0] = 0; for(int j = 0; j <= n; j++){ int w1 = 0, w2 = 0; for(int i = 1; i <= n; i++){ while(w2 < n && a[w2] <= a[i - 1] - w * 2) w2++; w1 = max(w1, w2); while(w1 < n && a[w1] <= a[i - 1] - w) w1++; if(j > 0) dp[i][j] = min(dp[i][j], dp[w2][j - 1]); dp[i][j] = min(dp[i][j], dp[w1][j] + 1); } for(int i = 1; i <= n; i++) dp[i][j + 1] = min(dp[i][j], dp[i][j + 1]); } return dp[n][q] <= p; } int main(){ cin >> n >> p >> q; p = min(n, p); q = min(n, q); for(int i = 0; i < n; i++){ int v; cin >> v; a.push_back(v); } sort(a.begin(), a.end()); int l, r; for(l = 0, r = 1e9 + 1; l != r;){ int m = (l + r) / 2; if(ok(m)){ r = m; }else{ l = m + 1; } } cout << l << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 724 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 3 ms | 724 KB | Output is correct |
5 | Correct | 3 ms | 724 KB | Output is correct |
6 | Correct | 3 ms | 724 KB | Output is correct |
7 | Correct | 3 ms | 688 KB | Output is correct |
8 | Correct | 3 ms | 724 KB | Output is correct |
9 | Correct | 3 ms | 724 KB | Output is correct |
10 | Correct | 3 ms | 724 KB | Output is correct |
11 | Correct | 3 ms | 724 KB | Output is correct |
12 | Correct | 3 ms | 724 KB | Output is correct |
13 | Correct | 2 ms | 724 KB | Output is correct |
14 | Correct | 2 ms | 724 KB | Output is correct |
15 | Correct | 2 ms | 724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1095 ms | 15956 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |