Submission #1015314

#TimeUsernameProblemLanguageResultExecution timeMemory
1015314overwatch9Watching (JOI13_watching)C++17
50 / 100
137 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int n; vector <int> events; vector <vector <vector <bool>>> dp; vector <vector <vector <int>>> ready; bool solve(int i, int p, int q, int w) { if (i >= n) return true; if (ready[i][p][q] == w) return dp[i][p][q]; bool ans = false; if (p >= 1) { int it = upper_bound(events.begin(), events.end(), events[i] + w - 1) - events.begin(); ans |= solve(it, p-1, q, w); } if (q >= 1) { int it = upper_bound(events.begin(), events.end(), events[i] + 2*w - 1) - events.begin(); ans |= solve(it, p, q-1, w); } ready[i][p][q] = w; dp[i][p][q] = ans; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int p, q; cin >> n >> p >> q; events = vector <int> (n); for (int i = 0; i < n; i++) cin >> events[i]; sort(events.begin(), events.end()); if (p + q >= n) { cout << 1 << '\n'; return 0; } dp = vector <vector <vector <bool>>> (n, vector <vector <bool>> (p+1, vector <bool> (q+1))); ready = vector <vector <vector <int>>> (n, vector <vector <int>> (p+1, vector <int> (q+1))); int lo = 1, hi = 1e9; while (lo < hi) { int mid = lo + (hi - lo) / 2; if (solve(0, p, q, mid)) hi = mid; else lo = mid + 1; } cout << lo << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...