Submission #1272626

#TimeUsernameProblemLanguageResultExecution timeMemory
1272626DeathIsAweWatching (JOI13_watching)C++20
100 / 100
971 ms4232 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define pf push_front #define mp make_pair #define ll long long int n, p, q; bool dpcheck(int w, vector<int> sections) { vector<vector<int>> dp(p + 1, vector<int>(q + 1)); dp[0][0] = 0; for (int i=1;i<p+1;i++) { if (dp[i - 1][0] == n) { dp[i][0] = n; continue; } dp[i][0] = upper_bound(sections.begin(), sections.end(), sections[dp[i - 1][0]] + w - 1) - sections.begin(); } for (int i=1;i<q+1;i++) { if (dp[0][i - 1] == n) { dp[0][i] = n; continue; } dp[0][i] = upper_bound(sections.begin(), sections.end(), sections[dp[0][i - 1]] + 2*w - 1) - sections.begin(); } for (int i=1;i<p+1;i++) { for (int j=1;j<q+1;j++) { if (dp[i][j - 1] == n || dp[i - 1][j] == n) { dp[i][j] = n; continue; } dp[i][j] = upper_bound(sections.begin(), sections.end(), sections[dp[i][j - 1]] + 2*w - 1) - sections.begin(); dp[i][j] = max(dp[i][j], (int)(upper_bound(sections.begin(), sections.end(), sections[dp[i - 1][j]] + w - 1) - sections.begin())); } } return (dp[p][q] == n); } int main() { cin >> n >> p >> q; vector<int> sections(n); for (int i=0;i<n;i++) { cin >> sections[i]; } sort(sections.begin(), sections.end()); if (p + q >= n) { cout << 1; } else { int top = 1000000000, bottom = 0, mid; while (top > bottom + 1) { mid = (top + bottom) / 2; if (dpcheck(mid, sections)) {top = mid;} else {bottom = mid;} } cout << top; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...