Submission #641170

#TimeUsernameProblemLanguageResultExecution timeMemory
641170cthbstLet's Win the Election (JOI22_ho_t3)C++14
21 / 100
965 ms8404 KiB
#include <algorithm> #include <iomanip> #include <iostream> #include <utility> #include <vector> using namespace std; #define int long long using pdd = pair<long double, long double>; const long double INF = 1e18; const int maxn = 505; int n, k; vector<pdd> vc; long double dp[maxn][maxn]; long double sf[maxn][maxn]; // sf[i][j] 從 A[i~(n-1)] 選 j 個最小的數字 void build_sf() { for (int i = 1; i < maxn; i++) { fill(sf[i] + 1, sf[i] + maxn, INF); } for (int i = n - 1; i >= 0; i--) { vector<long double> cur; for (int j = i; j < n; j++) { cur.push_back(vc[j].first); } sort(cur.begin(), cur.end()); sf[i][0] = 0; for (int j = 1; j <= k; j++) { if (j > (int)(cur.size())) break; else sf[i][j] = sf[i][j - 1] + cur[j - 1]; } } } long double solve(const int t) { for (int i = 0; i < n; i++) { fill(dp[i], dp[i] + (t + 1), INF); } for (int i = 0; i < n; i++) { if (i == 0) { dp[i][0] = vc[i].first / (t + 1.0); dp[i][1] = vc[i].second; continue; } for (int j = 0; j <= t; j++) { if (j == 0) { dp[i][0] = dp[i - 1][0] + vc[i].first / (t + 1.0); } else { long double x = dp[i - 1][j] + vc[i].first / (t + 1.0); long double y = dp[i - 1][j - 1] + vc[i].second * 1.0 / j; dp[i][j] = min(x, y); } } } if (k == n) { return dp[n - 1][t]; } long double res = sf[0][k]; for (int i = t - 1; i < n - k + t; i++) { res = min(res, dp[i][t] + sf[i + 1][k - t] / (t + 1.0)); } return res; } signed main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); cin >> n >> k; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (y == -1) { vc.push_back({x, INF}); } else { vc.push_back({x, y}); } } sort(vc.begin(), vc.end(), [](pdd a, pdd b) { return a.second < b.second; }); build_sf(); long double res = sf[0][k]; for (int t = 1; t <= k; t++) { res = min(res, solve(t)); } cout << res << '\n'; 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...