# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
278252 |
2020-08-21T11:28:27 Z |
erray |
Watching (JOI13_watching) |
C++17 |
|
638 ms |
16184 KB |
// author: erray
#include<bits/stdc++.h>
#undef DEBUG
using namespace std;
template<typename T, typename F> string to_string(pair<T, F> p);
string to_string(string s) {
return '"' + s + '"';
}
string to_string(char c) {
return (string) "'" + c + "'";
}
string to_string(const char* p) {
return to_string((string) p);
}
string to_string(bool B) {
return (B ? "true" : "false");
}
string to_string(vector<bool> v) {
string res = "{";
for (int i = 0; i < (int) v.size(); ++i) {
if ((int) res.size() > 1) res += ", ";
res += to_string(v[i]);
}
res += "}";
return res;
}
template<size_t T> string to_string(bitset<T> bs) {
return bs.to_string();
}
template<typename T> string to_string(T v) {
string res = "{";
for (auto& el : v) {
if ((int) res.size() > 1) res += ", ";
res += to_string(el);
}
res += "}";
return res;
}
template<typename T, typename F> string to_string(pair<T, F> p) {
return '(' + to_string(p.first) + ", " + to_string(p.second) + ')';
}
void debug_out() {
cerr << endl;
}
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" , debug_out(__VA_ARGS__)
#else
#define debug(...) (void) 37
#endif
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, p, q;
cin >> n >> p >> q;
p = min(p, n);
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a.begin(), a.end());
auto check = [&](long long l) {
vector<vector<int>> dp(n, vector<int>(p + 1, INT_MAX));
auto get = [&](int x, int y) {
if (y > p) return (int) 1e9;
if (x == n) return 0;
return dp[x][y];
};
int p1 = n - 1, p2 = n - 1;
for (int i = n - 1; i >= 0; --i) {
while (p1 > 0 && a[p1] >= a[i] + l) --p1;
while (p2 > 0 && a[p2] >= a[i] + 2 * l) --p2;
debug(i, p1, p2);
for (int j = 0; j <= p; ++j) {
dp[i][j] = get(p1 + 1, j + 1);
dp[i][j] = min(dp[i][j], get(p2 + 1, j) + 1);
}
}
debug(dp);
return dp[0][0] <= q;
};
int s = 1, e = (int) 1e9;
while (s != e) {
int mid = (s + e) >> 1;
if (check(mid)) e = mid;
else s = mid + 1;
debug(s, e);
}
cout << s << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
392 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
493 ms |
12416 KB |
Output is correct |
4 |
Correct |
637 ms |
16184 KB |
Output is correct |
5 |
Correct |
25 ms |
1088 KB |
Output is correct |
6 |
Correct |
604 ms |
16184 KB |
Output is correct |
7 |
Correct |
7 ms |
512 KB |
Output is correct |
8 |
Correct |
37 ms |
1456 KB |
Output is correct |
9 |
Correct |
230 ms |
6424 KB |
Output is correct |
10 |
Correct |
638 ms |
15460 KB |
Output is correct |
11 |
Correct |
28 ms |
1268 KB |
Output is correct |
12 |
Correct |
341 ms |
8404 KB |
Output is correct |
13 |
Correct |
7 ms |
512 KB |
Output is correct |
14 |
Correct |
8 ms |
640 KB |
Output is correct |
15 |
Correct |
7 ms |
512 KB |
Output is correct |