Submission #1216365

#TimeUsernameProblemLanguageResultExecution timeMemory
1216365trimkusLet's Win the Election (JOI22_ho_t3)C++20
61 / 100
2595 ms4424 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; ld dp[2][501][501]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; //~ cerr << "A\n"; vector<array<ld, 2>> a(n); int cnt = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < 2; ++j) { cin >> a[i][j]; } cnt += (a[i][1] != -1); swap(a[i][0], a[i][1]); } sort(begin(a), end(a)); auto chmin = [&](ld& x, ld y) -> void { x = min(x, y); }; //~ cerr << "a\n"; int left = 0, right = min(k, cnt) - 1; int res = min(k, cnt); auto calc = [&](int take) -> ld { for (int i = 0; i < 2; ++i) { for (int j = 0; j <= k - take; ++j) { for (int z = 0; z <= take; ++z) { dp[i][j][z] = 1e18; } } } dp[0][0][0] = 0; for (int j = 0; j < n; ++j) { int p = j & 1; for (int l = 0; l <= k - take; ++l) { for (int z = 0; z <= take; ++z) { dp[p ^ 1][l][z] = dp[p][l][z]; if (l > 0) { chmin(dp[p ^ 1][l][z], dp[p][l - 1][z] + a[j][1] / (take + 1)); } if (a[j][0] != -1 && z > 0) { chmin(dp[p ^ 1][l][z], dp[p][l][z - 1] + a[j][0] / z); } } } } //~ cerr << take << " = " << dp[n & 1][k][take] << "\n"; return dp[n & 1][k - take][take]; }; while (left <= right) { int m = (left + right) / 2; if (calc(m) <= calc(m + 1)) { right = m - 1; res = m; } else { left = m + 1; } } cout << fixed << setprecision(3) << calc(res) << "\n"; }
#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...