제출 #278252

#제출 시각아이디문제언어결과실행 시간메모리
278252erray구경하기 (JOI13_watching)C++17
100 / 100
638 ms16184 KiB
// 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...