Submission #1233661

#TimeUsernameProblemLanguageResultExecution timeMemory
1233661coin_Watching (JOI13_watching)C++20
100 / 100
570 ms30444 KiB
#include <bits/stdc++.h> #define endl '\n' #define int long long #define fi first #define se second #define pb push_back using namespace std; bool check(int n, int p, int q, vector<int> a, int w){ vector<vector<int>> dp(n+5, vector<int>(p+5, 0)); dp[0][0] = 1; for (int i = 1; i < n; i++){ int lastSmall = 0, lastBig = 0; for (int j = 0; j <= i; j++){ if (a[i] - a[j] >= w){ lastSmall++; } else{ break; } } for (int j = 0; j <= i; j++){ if (a[i] - a[j] >= 2*w){ lastBig++; } else{ break; } } // no small cams, forced to use big dp[i][0] = (lastBig == 0 ? 1LL : dp[lastBig-1][0] + 1LL); for (int j = 1; j <= p; j++){ if (lastSmall == 0){ // place 1 small camera, will definitely have 1 small cam availible => 0 large cams dp[i][j] = 0LL; } else if (lastBig == 0){ // either use 1 large camera or use 1 small cam dp[i][j] = min(dp[lastSmall-1][j-1], 1LL); } else dp[i][j] = min(dp[lastSmall-1][j-1], dp[lastBig-1][j] + 1); } } int ans = 100000000; for (int i = 0; i <= p; i++){ ans = min(ans, dp[n-1][i]); } return ans <= q; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while(t--){ // p - small, q - large int n, p, q; cin >> n >> p >> q; vector<int> a(n); for (int i = 0; i < n; i++){ cin >> a[i]; } sort(a.begin(), a.end()); if (p + q >= n){ cout << 1; break; } int l = 1, r = 1000000001; while(l < r){ int mid = (l + r) / 2; if (check(n, p, q, a, mid)){ r = mid; } else{ l = mid + 1; } } cout << r; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...