# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1033284 |
2024-07-24T15:59:52 Z |
adaawf |
Watching (JOI13_watching) |
C++17 |
|
153 ms |
15964 KB |
#include <iostream>
#include <algorithm>
using namespace std;
int n, p, q, a[2005], f[2005][2005];
bool check(int x) {
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= p; j++) {
f[i][j] = 1e9;
}
}
for (int i = 1; i <= n; i++) {
int h = upper_bound(a + 1, a + n + 1, a[i] - x) - a, k = upper_bound(a + 1, a + n + 1, a[i] - x * 2) - a;
//cout << h << " " << k << " " << x << " " << i << '\n';
for (int j = 0; j <= p; j++) {
if (j != 0) f[i][j] = min(f[i][j], f[h - 1][j - 1]);
f[i][j] = min(f[i][j], f[k - 1][j] + 1);
//cout << i << " " << j << " " << f[i][j] << '\n';
}
}
for (int j = 0; j <= p; j++) {
if (f[n][j] <= q) return true;
}
return false;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> p >> q;
for (int i =1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
if (p + q >= n) {
cout << 1;
return 0;
}
int l = 1, r = 1e9, res;
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid) == true) {
res = mid;
r = mid - 1;
}
else l = mid + 1;
}
cout << res;
}
Compilation message
watching.cpp: In function 'int main()':
watching.cpp:46:13: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
46 | cout << res;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
860 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 |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
860 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Correct |
1 ms |
856 KB |
Output is correct |
12 |
Correct |
1 ms |
860 KB |
Output is correct |
13 |
Correct |
0 ms |
860 KB |
Output is correct |
14 |
Correct |
0 ms |
860 KB |
Output is correct |
15 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8284 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
8536 KB |
Output is correct |
8 |
Correct |
18 ms |
9304 KB |
Output is correct |
9 |
Correct |
66 ms |
14380 KB |
Output is correct |
10 |
Correct |
153 ms |
15964 KB |
Output is correct |
11 |
Correct |
15 ms |
9052 KB |
Output is correct |
12 |
Correct |
83 ms |
15964 KB |
Output is correct |
13 |
Correct |
8 ms |
8540 KB |
Output is correct |
14 |
Correct |
9 ms |
8540 KB |
Output is correct |
15 |
Correct |
9 ms |
8536 KB |
Output is correct |