Submission #503185

#TimeUsernameProblemLanguageResultExecution timeMemory
503185Abrar_Al_Samit구경하기 (JOI13_watching)C++17
50 / 100
10 ms8648 KiB
#include<bits/stdc++.h> using namespace std; const int MX = 101; int n; vector<int>a; int dp[MX][MX][MX]; int jump[MX][2]; bool solve(int i, int p, int q) { if(i==n) return 1; if(p+q==0) return 0; int &ret = dp[i][p][q]; if(ret!=-1) return ret; ret = 0; if(p) ret = solve(jump[i][0], p-1, q); if(q) ret |= solve(jump[i][1], p, q-1); return ret; } void PlayGround() { int p, q; cin >> n >> p >> q; if(p+q>=n) { cout << "1\n"; return; } for(int i=0; i<n; ++i) { int x; cin >> x; a.push_back(x); } sort(a.begin(), a.end()); int l=1, r=1e9; while(l<r) { int w = (l+r)/2; for(int i=0; i<n; ++i) { jump[i][0] = lower_bound(a.begin(), a.end(), a[i]+w) - a.begin(); jump[i][1] = lower_bound(a.begin(), a.end(), a[i]+w+w) - a.begin(); } memset(dp, -1, sizeof dp); if(solve(0, p, q)) { r = w; } else { l = w+1; } } cout << l << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...