# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
56517 | 2018-07-11T14:45:30 Z | luciocf | Watching (JOI13_watching) | C++14 | 1000 ms | 12628 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2010; int n, p, q, num[MAXN]; int dp[MAXN][MAXN]; int busca2(int k) { if (k > num[n]) return n; int ini = 1, fim = n, ans; while (ini <= fim) { int mid = (ini+fim)>>1; if (num[mid] <= k) ans = mid, ini = mid+1; else fim = mid-1; } return ans; } bool ok(int w) { for (int i = 1; i <= p; i++) for (int j = 1; j <= q; j++) dp[i][j] = 1; for (int i = 0; i <= p; i++) dp[i][0] = 0; for (int j = 0; j <= q; j++) dp[0][j] = 0; for (int i = 0; i <= p; i++) { for (int j = 0; j <= q; j++) { if (!i && !j) continue; if (i) dp[i][j] = busca2(num[dp[i-1][j]+1]+w-1); if (j) dp[i][j] = max(dp[i][j], busca2(num[dp[i][j-1]+1]+2*w-1)); } } return (dp[p][q] >= n); } int busca(void) { int ini = 1, fim = 1e9, ans; while (ini <= fim) { int mid = (ini+fim)>>1; if (ok(mid)) ans = mid, fim = mid-1; else ini = mid+1; } return ans; } int main(void) { cin >> n >> p >> q; for (int i = 1; i <= n; i++) cin >> num[i]; if (p >= n || q >= n) { cout << "1\n"; return 0; } sort(num+1, num+n+1); cout << busca() << "\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 504 KB | Output is correct |
2 | Correct | 3 ms | 608 KB | Output is correct |
3 | Correct | 3 ms | 624 KB | Output is correct |
4 | Correct | 2 ms | 676 KB | Output is correct |
5 | Correct | 2 ms | 676 KB | Output is correct |
6 | Correct | 3 ms | 908 KB | Output is correct |
7 | Incorrect | 3 ms | 1024 KB | Output isn't correct |
8 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 1024 KB | Output is correct |
2 | Correct | 3 ms | 1024 KB | Output is correct |
3 | Execution timed out | 1084 ms | 12628 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |