| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1294440 | harryleee | 구경하기 (JOI13_watching) | C++20 | 74 ms | 14284 KiB |
#include <bits/stdc++.h>
using namespace std;
#define NAME "A"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
const int N = 2005;
const int inf = 1e9;
int n, p, q;
int a[N], pos[N][2];
int dp[N][N];
bool f(int w) {
for (int i = 1; i <= n; i++) {
pos[i][0] = upper_bound(a + 1, a + 1 + n, a[i] + w - 1) - a - 1;
pos[i][1] = upper_bound(a + 1, a + 1 + n, a[i] + 2 * w - 1) - a - 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
dp[i][j] = inf;
}
}
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= min(i, p); j++) {
if (dp[i][j] == inf) continue;
if (j + 1 <= p) {
if (pos[i + 1][0] >= n) return 1;
dp[pos[i + 1][0]][j + 1] = min(dp[pos[i + 1][0]][j + 1], dp[i][j]);
}
if (dp[i][j] + 1 <= q) {
if (pos[i + 1][1] >= n) return 1;
dp[pos[i + 1][1]][j] = min(dp[pos[i + 1][1]][j], dp[i][j] + 1);
}
}
}
return 0;
}
void input() {
cin >> n >> p >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + 1 + n);
}
void solve() {
if (p + q >= n) {
cout << 1;
return;
}
int l = 1, r = 1e9, ans = 1e9;
while (l <= r) {
int mid = (l + r) >> 1;
if (f(mid)) {
ans = mid;
r = mid - 1;
}
else {
l = mid + 1;
}
}
cout << ans;
}
signed main() {
if (fopen(NAME".INP", "r")) {
freopen(NAME".INP", "r", stdin);
freopen(NAME".OUT", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
input();
solve();
return 0;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
