Submission #733737

#TimeUsernameProblemLanguageResultExecution timeMemory
733737shoryu386Let's Win the Election (JOI22_ho_t3)C++17
56 / 100
2630 ms996520 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define db float #define MAX 502 basic_string<db> dp[MAX][MAX]; int n, k; pair<db, db> info[MAX]; int maxcolab; bool cmp(pair<db, db> a, pair<db, db> b){ if (a.second == -1) a.second = 1000000000; if (b.second == -1) b.second = 1000000000; return a.second < b.second; } db recur(int idx, int colabCount, int voteCount){ #define cringe info if (maxcolab < colabCount) return 1000000000; if (voteCount > k) return 1000000000; if (idx == n && voteCount == k && maxcolab == colabCount) return 0; else if (idx == n) return 1000000000; if (dp[idx][colabCount][voteCount] != -1) return dp[idx][colabCount][voteCount]; if (cringe[idx].second == -1) return dp[idx][colabCount][voteCount] = min(recur(idx+1, colabCount, voteCount), recur(idx+1, colabCount, voteCount+1) + cringe[idx].first/maxcolab); return dp[idx][colabCount][voteCount] = min({recur(idx+1, colabCount, voteCount), recur(idx+1, colabCount, voteCount+1) + cringe[idx].first/maxcolab, recur(idx+1, colabCount+1, voteCount+1) + cringe[idx].second/colabCount}); } db ans = 1000000000000000LL; db query(int x){ for (int a = 0; a <= n; a++) for (int y = 0; y <= n+1; y++) {dp[a][y].clear(); dp[a][y].reserve(n); for (int z = 0; z <= n; z++) dp[a][y].push_back(-1);} maxcolab = x; db r = recur(0, 1, 0); ans = min(ans, r); return r; } signed main(){ cin >> n >> k; for (int x = 0; x < n; x++) cin >> info[x].first >> info[x].second; sort(info, info+n, cmp); int l = 1, r = n+1; while (r - l >= 3){ int m1 = l + (r-l)/3; int m2 = r - (r-l)/3; if (query(m1) > query(m2)){ l = m1; } else{ r = m2; } } for (int i = l; i <= r; i++){ ans = min(ans, query(i)); } cout << std::setprecision(9) << ans; }
#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...