Submission #691301

#TimeUsernameProblemLanguageResultExecution timeMemory
691301yaufungLet's Win the Election (JOI22_ho_t3)C++17
100 / 100
457 ms2752 KiB
#include <bits/stdc++.h> using namespace std; double solve(int n, int k, vector<pair<int, int>> &a, int totalB) { vector<vector<double>> dp(n + 1, vector<double>(n + 1, 1e9)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int As = 0; As <= min(i - 1, k - totalB); As++) { int Bs = min(totalB, i - 1 - As); if (As < k - totalB) { double d = a[i].first; dp[i][As + 1] = min(dp[i][As + 1], dp[i - 1][As] + d / (totalB + 1)); } if (Bs < totalB) { double d = a[i].second; dp[i][As] = min(dp[i][As], dp[i - 1][As] + d / (Bs + 1)); } else dp[i][As] = min(dp[i][As], dp[i - 1][As]); } } return dp[n][k - totalB]; } int main() { ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<pair<int, int>> a(n + 1, {0, 0}); for (int i = 1; i <= n; i++) { cin >> a[i].second >> a[i].first; if (a[i].first == -1) a[i].first = 1e9; } sort(a.begin(), a.end()); for (int i = 1; i <= n; i++) { swap(a[i].first, a[i].second); } double ans = 1e9; for (int i = 0; i <= k; i++) { ans = min(ans, solve(n, k, a, i)); } cout << setprecision(10) << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...