# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
638577 | ghostwriter | Watching (JOI13_watching) | C++14 | 405 ms | 16032 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
Tran The Bao
CTL - Da Lat
Cay ngay cay dem nhung deo duoc cong nhan
*/
const int oo = 1e9;
const int N = 2e3 + 2;
int n, p, q, a[N], d[N][N], f[N], f1[N];
bool check(int w) {
FOR(i, 1, n) {
FOS(j, i, 1) {
if (a[j] >= a[i] - w + 1) f[i] = j;
if (a[j] >= a[i] - 2 * w + 1) f1[i] = j;
}
}
FOR(i, 1, n)
FOR(j, 0, p) {
d[i][j] = oo;
if (j) {
int pos = f[i];
d[i][j] = min(d[i][j], d[pos - 1][j - 1]);
}
int pos = f1[i];
d[i][j] = min(d[i][j], d[pos - 1][j] + 1);
}
return d[n][p] <= q;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
cin >> n >> p >> q;
FOR(i, 1, n) cin >> a[i];
sort(a + 1, a + 1 + n);
p = min(p, n);
q = min(q, n);
int l = 1, r = 1e9, ans = -1;
WHILE(l <= r) {
int mid = l + (r - l) / 2;
if (check(mid)) {
ans = mid;
r = mid - 1;
}
else l = mid + 1;
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |