Submission #1322056

#TimeUsernameProblemLanguageResultExecution timeMemory
1322056i_love_springWatching (JOI13_watching)C++20
50 / 100
1096 ms4196 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array #define all(x) x.begin(), x.end() const int inf = 2e9 + 5; static int dp[2005], ndp[2005], a[2005]; deque<ar<int, 2>> sm[2008], big[2008]; int n, p, q; int f(int w) { for (int i = 0; i <= q;i++) ndp[i] = p + 10; ndp[0] = 0; for (int i = 0; i <= q;i++) { while (!sm[i].empty()) sm[i].pop_back(); while (!big[i].empty()) big[i].pop_back(); } for (int i = 1; i <= n;i++) { for (int j = 0; j <= q;j++) { dp[j] = ndp[j]; ndp[j] = p + 10; } for (int j = 0; j <= q;j++) { while (!sm[j].empty()) { auto [x, id] = sm[j].front(); if (a[i] - a[id] + 1 <= w) break; sm[j].pop_front(); } while (!big[j].empty()) { auto [x, id] = big[j].front(); if (a[i] - a[id] + 1 <= w * 2) break; big[j].pop_front(); } while (!sm[j].empty()) { auto [x, id] = sm[j].back(); if (x < dp[j]) break; sm[j].pop_back(); } while (!big[j].empty()) { auto [x, id] = big[j].back(); if (x < dp[j]) break; big[j].pop_back(); } sm[j].push_back({dp[j], i}); big[j].push_back({dp[j], i}); if (!sm[j].empty()) ndp[j] = min(ndp[j], (sm[j].front())[0] + 1); if (j > 0 && !big[j - 1].empty()) ndp[j] = min(ndp[j], (big[j - 1].front())[0]); } } int ans = inf; for (int i = 0; i <= q;i++) ans = min(ans, ndp[i]); return ans; } void solve() { cin >> n >> p >> q; a[0] = 0; for (int i = 1; i <= n;i++) cin >> a[i]; if (p + q >= n) return (void)(cout << 1); sort(a + 1, a + n + 1); // for (int i = 0; i <= n;i++) cout << a[i] << " "; int l = 1, r = a[n] - a[1] + 1, ans = a[n] - a[1] + 1; while (l <= r) { int m = (l + r) / 2; if (f(m) <= p) r = m - 1, ans = m; else l = m + 1; } cout << ans; } signed main() { ios :: sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) { solve(); cout << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...