Submission #976357

#TimeUsernameProblemLanguageResultExecution timeMemory
976357vjudge1구경하기 (JOI13_watching)C++17
0 / 100
53 ms604 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define lld double #define int ll #define usaco(fname) freopen(#fname ".in","r",stdin);freopen(#fname ".out","w",stdout); template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } // const ll INF = 1e18; const int INF = 1e18; const int mod = 1e9+7; const lld PI = acos(-1.0); int di[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dj[] = {0, 0, 1, -1, 1, -1, 1, -1}; #define debug(x) cout << #x << ": " << x << endl; #define add(a, b) a += b, a %= mod #define mul(a, b) ((a % mod) * (b % mod)) % mod #define all(x) x.begin(),x.end() void solve() { int n,p,q;cin>>n>>p>>q; vector<int> a(n); for (int i =0 ; i < n; i++) cin >> a[i]; sort(all(a)); function<bool(int)> chk = [&](int k) { vector<int> dp(n, INF); // fewest q to cover all for (int i = 0; i < n; i++) { int before = (i-1 >= 0 ? dp[i-1] : 0); int j = i; for (; j < n; j++) { if (a[i]+2*k-1 < a[j]) break; dp[j] = min(dp[j], before+1); } } if (dp[n-1] <= q) return true; // cout << dp endl; map<int, int> cnt; for (int i = 0; i < n; i++) cnt[dp[i]]++; vector<pair<int, int>> bruh(all(cnt)); sort(all(bruh), [&](auto &x, auto &y) { return x.second > y.second; }); set<int> dontcount; for (int i = 0; i < q; i++) dontcount.insert(bruh[i].first); vector<int> newa; for (int i = 0; i < n; i++) { if (dontcount.count(dp[i])) continue; newa.push_back(a[i]); } int sz = newa.size(); vector<int> dp2(sz, INF); for (int i = 0; i < sz; i++) { int before = (i-1 >= 0 ? dp2[i-1] : 0); int j = i; for (; j < sz; j++) { if (newa[i]+k-1 < newa[j]) break; dp2[j] = min(dp2[j], before+1); } } return dp2[sz-1] <= p; }; int ans = 1e9+69; int l = 1, r = 1e9+69; while (l <= r) { int mid = (l+r)>>1; if (chk(mid)) { r = mid-1; ans = mid; } else l = mid+1; } cout << ans << endl; } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0); int t=1; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...