Submission #377032

#TimeUsernameProblemLanguageResultExecution timeMemory
377032SavicSWatching (JOI13_watching)C++14
100 / 100
202 ms16236 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ff(i,a,b) for(int i=a;i<=b;i++) #define fb(i,b,a) for(int i=b;i>=a;i--) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int,int> pii; const int maxn = 2005; const int inf = 1e9 + 5; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) int n, p, q; ll niz[maxn]; // p, q <= 1e5 i n <= 2000 // naive: n^2 * p * q // za a malih kamera, koliko mi treba velikih da slikam prvih i proslova - dp[a][i] // dp[a][i] <= q return 1, else return 0 int dp[maxn][maxn]; bool check(ll x){ int jp = 1; int jq = 1; memset(dp, 0, sizeof(dp)); ff(i,1,n){ while(niz[i] - niz[jp] >= x)jp += 1; while(niz[i] - niz[jq] >= 2 * x)jq += 1; ff(j,0,p){ if(j != 0){ // ili uradim sa malom kamerom [jp, i] // ili uradim sa velikom kamerom [jq, i], ali dodam jedan dp[i][j] = min(dp[jp - 1][j - 1], dp[jq - 1][j] + 1); } else dp[i][j] = dp[jq - 1][j] + 1; } } int mn = inf; ff(j,0,p)mn = min(mn, dp[n][j]); return mn <= q; } int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> n >> p >> q; ff(i,1,n)cin >> niz[i]; if(p + q >= n)return cout << 1, 0; sort(niz + 1, niz + n + 1); int l = 1, r = inf, ans = inf; while(l <= r){ int mid = (l + r) / 2; if(check(mid)){ ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans << endl; return 0; } /** 3 1 1 2 11 17 // probati bojenje sahovski ili slicno **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...