이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: chowgz
* created: 06/11/2021 20:19:08
**/
#include <bits/stdc++.h>
using namespace std;
int n, p, q;
const int MAXN = 2'000;
int arr[MAXN + 5];
int m;
map<long long, bool> mmap;
long long hsh(int x, int y, int z) {
return x * 3'000 * 3'000 + y * 3'000 + z;
}
bool dp(int x, int y, int z) {
// x: considering arr[x], y: # short pieces left, z: # long pieces left
#ifdef LOCAL
cerr << "x: " << x << " y: " << y << " z: " << z << endl;
#endif
if (y < 0 || z < 0) {
return false;
}
if (y + z >= n - x) {
return true;
}
if (mmap.find(hsh(x, y, z)) != mmap.end()) {
return mmap[hsh(x, y, z)];
}
return mmap[hsh(x, y, z)]
= dp(upper_bound(arr, arr + n, arr[x] + m - 1) - arr, y - 1, z) // use short
|| dp(upper_bound(arr, arr + n, arr[x] + 2 * m - 1) - arr, y, z - 1);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> p >> q;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
if (p + q >= n) {
cout << 1 << '\n';
return 0;
}
sort(arr, arr + n);
int l = 1, r = 1'000'000'000;
while (l != r) {
m = (l + r) / 2;
mmap.clear();
if (dp(0, p, q)) {
r = m;
} else {
l = m + 1;
}
}
cout << l << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |