# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
34572 | 2017-11-13T04:39:41 Z | sinhriv | Watching (JOI13_watching) | C++14 | 1000 ms | 20968 KB |
#include <bits/stdc++.h> using namespace std; const int N = 2202; int n, p, q; int a[N]; int f[N][N]; int main(){ if(fopen("1.inp", "r")){ freopen("1.inp", "r", stdin); } scanf("%d%d%d", &n, &p, &q); for(int i = 1; i <= n; ++i){ scanf("%d", a + i); } p = min(p, n); q = min(q, n); sort(a + 1, a + n + 1); int low = 1, high = 1e9, ans = 1e9; while(low <= high){ int w = (low + high) >> 1; memset(f, 60, sizeof f); f[0][0] = 0; bool ok = false, debug = false; for(int j = 0; j <= p; ++j){ deque < int > one, two; for(int i = 1; i <= n; ++i){ while(!one.empty() && a[i] - a[one.front() + 1] + 1 > w){ one.pop_front(); } while(!two.empty() && a[i] - a[two.front() + 1] + 1 > w + w){ two.pop_front(); } if(j > 0){ while(!one.empty() && f[one.back()][j - 1] >= f[i - 1][j - 1]) one.pop_back(); one.push_back(i - 1); } while(!two.empty() && f[two.back()][j] >= f[i - 1][j]) two.pop_back(); two.push_back(i - 1); if(!one.empty()) f[i][j] = min(f[i][j], f[one.front()][j - 1]); if(!two.empty()) f[i][j] = min(f[i][j], f[two.front()][j] + 1); if(i == n && f[i][j] <= q){ ok = true; } } } if(ok == false){ low = w + 1; } else{ ans = w; high = w - 1; } } cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 20968 KB | Output is correct |
2 | Correct | 76 ms | 20968 KB | Output is correct |
3 | Correct | 49 ms | 20968 KB | Output is correct |
4 | Correct | 106 ms | 20968 KB | Output is correct |
5 | Correct | 93 ms | 20968 KB | Output is correct |
6 | Correct | 73 ms | 20968 KB | Output is correct |
7 | Correct | 86 ms | 20968 KB | Output is correct |
8 | Correct | 69 ms | 20968 KB | Output is correct |
9 | Correct | 63 ms | 20968 KB | Output is correct |
10 | Correct | 73 ms | 20968 KB | Output is correct |
11 | Correct | 83 ms | 20968 KB | Output is correct |
12 | Correct | 73 ms | 20968 KB | Output is correct |
13 | Correct | 103 ms | 20968 KB | Output is correct |
14 | Correct | 63 ms | 20968 KB | Output is correct |
15 | Correct | 89 ms | 20968 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 99 ms | 20968 KB | Output is correct |
2 | Correct | 46 ms | 20968 KB | Output is correct |
3 | Execution timed out | 1000 ms | 20968 KB | Execution timed out |
4 | Halted | 0 ms | 0 KB | - |