# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863942 | 2023-10-21T13:52:35 Z | prohacker | Watching (JOI13_watching) | C++14 | 204 ms | 16216 KB |
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int N = 2010; const int INF = INT_MAX; const int mod = 1e9+7; int n,p,q,a[N]; int dp[N][N]; bool check(int mid) { for(int i = 1 ; i <= n ; i++) { for(int j = 0 ; j <= q ; j++) { dp[i][j] = mod; } } for(int i = 1, j = 1, k = 1 ; i <= n ; i++) { while(j < i && a[i]-a[j] >= mid) { j++; } while(k < i && a[i]-a[k] >= mid*2) { k++; } for(int l = 0 ; l <= q ; l++) { dp[i][l] = dp[j-1][l]+1; } for(int l = 0 ; l <= q ; l++) { dp[i][l+1] = min(dp[i][l+1],dp[k-1][l]); } } for(int i = 0 ; i <= q ; i++) { if(dp[n][i] <= p) { return true; } } return false; } signed main() { if (fopen("WATCHING.inp", "r")) { freopen("WATCHING.inp", "r", stdin); freopen("WATCHING.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> p >> q; if(n <= p+q) { cout << 1; return 0; } for(int i = 1 ; i <= n ; i++) { cin >> a[i]; } sort(a+1,a+n+1); int l = 1; int r = 1e9; int ans; while(l <= r) { int mid = l + r >> 1; if(check(mid)) { ans = mid; r = mid-1; } else { l = mid+1; } } cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2396 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 | 344 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2396 KB | Output is correct |
9 | Correct | 1 ms | 2392 KB | Output is correct |
10 | Correct | 1 ms | 2396 KB | Output is correct |
11 | Correct | 1 ms | 2396 KB | Output is correct |
12 | Correct | 1 ms | 2396 KB | Output is correct |
13 | Correct | 1 ms | 2428 KB | Output is correct |
14 | Correct | 1 ms | 2396 KB | Output is correct |
15 | Correct | 1 ms | 2396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 15452 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 | 476 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 4 ms | 15452 KB | Output is correct |
8 | Correct | 80 ms | 15964 KB | Output is correct |
9 | Correct | 16 ms | 15452 KB | Output is correct |
10 | Correct | 14 ms | 15616 KB | Output is correct |
11 | Correct | 204 ms | 16216 KB | Output is correct |
12 | Correct | 113 ms | 16192 KB | Output is correct |
13 | Correct | 5 ms | 15448 KB | Output is correct |
14 | Correct | 4 ms | 15448 KB | Output is correct |
15 | Correct | 5 ms | 15452 KB | Output is correct |