# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1031730 |
2024-07-23T05:54:24 Z |
juicy |
Watching (JOI13_watching) |
C++17 |
|
40 ms |
16216 KB |
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N, P, Q; cin >> N >> P >> Q;
P = min(P, N);
Q = min(Q, N);
vector<int> A(N);
for (int i = 0; i < N; ++i) {
cin >> A[i];
}
sort(A.begin(), A.end());
vector dp(P + 1, vector<int>(Q + 1));
vector<array<int, 2>> nxt(N);
auto check = [&](int md) {
nxt[N - 1][0] = nxt[N - 1][1] = N - 1;
for (int i = N - 2; ~i; --i) {
for (int j = 1; j <= 2; ++j) {
int &p = nxt[i][j - 1];
p = nxt[i + 1][j - 1];
while (A[p] - A[i] >= j * md) {
--p;
}
}
}
for (int i = 0; i <= P; ++i) {
fill(dp[i].begin(), dp[i].end(), -1);
}
dp[0][0] = 0;
for (int i = 0; i <= P; ++i) {
for (int j = 0; j <= Q; ++j) {
if (dp[i][j] != -1) {
if (dp[i][j] == N) {
return true;
}
if (i + 1 <= P) {
dp[i + 1][j] = max(dp[i + 1][j], nxt[dp[i][j]][0] + 1);
}
if (j + 1 <= Q) {
dp[i][j + 1] = max(dp[i][j + 1], nxt[dp[i][j]][1] + 1);
}
}
}
}
return false;
};
int l = 1, r = 1e9, res = 1e9;
while (l <= r) {
int md = (l + r) / 2;
if (check(md)) {
res = md;
r = md - 1;
} else {
l = md + 1;
}
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
26 ms |
9308 KB |
Output is correct |
4 |
Correct |
8 ms |
1116 KB |
Output is correct |
5 |
Correct |
1 ms |
860 KB |
Output is correct |
6 |
Correct |
19 ms |
16216 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
6 ms |
852 KB |
Output is correct |
9 |
Correct |
7 ms |
860 KB |
Output is correct |
10 |
Correct |
10 ms |
1212 KB |
Output is correct |
11 |
Correct |
5 ms |
1116 KB |
Output is correct |
12 |
Correct |
40 ms |
4280 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |