Submission #937735

#TimeUsernameProblemLanguageResultExecution timeMemory
937735Gromp15Let's Win the Election (JOI22_ho_t3)C++17
61 / 100
2536 ms1264 KiB
#include <bits/stdc++.h> #define ll long long #define ar array #define db double #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rint(l, r) uniform_int_distribution<int>(l, r)(rng) template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } void test_case() { int n, k; cin >> n >> k; vector<ar<int, 2>> a(n); for (auto &x : a) cin >> x[0] >> x[1]; // let us use z people in the end // then, we must first take z-1 Bs, and those Bs will be taken in increasing order // As must be taken afterwards and can be taken in arbitrary order db ans = 1e18; int cnt = 0; for (int i = 0; i < n; i++) cnt += bool(~a[i][1]); sort(all(a), [&](const auto &A, const auto &B) { return A[1] < B[1]; }); for (int i = 1; i <= min(cnt, k) + 1; i++) { vector<vector<db>> dp(k+1, vector<db>(i+1, 1e18)); dp[0][1] = 0; for (int j = 0; j < n; j++) { for (int got = k-1; got >= 0; got--) { for (int l = 1; l <= i; l++) { if (~a[j][1] && l + 1 <= i) { ckmin(dp[got+1][l+1], dp[got][l] + (db)a[j][1] / l); } ckmin(dp[got+1][l], dp[got][l] + (db)a[j][0] / i); } } } ckmin(ans, dp[k][i]); } cout << fixed << setprecision(10) << ans << '\n'; } int main() { cin.tie(0)->sync_with_stdio(0); int t = 1; // cin >> t; while (t--) test_case(); }
#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...