Submission #593665

#TimeUsernameProblemLanguageResultExecution timeMemory
593665piOOELet's Win the Election (JOI22_ho_t3)C++17
56 / 100
109 ms8284 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; const int N = 101; db dp[N][N][N]; //id, b, a int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, K; cin >> n >> K; vector<int> a(n), b(n), oa(n), ob(n); int cntb = 0; for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; if (b[i] != -1) { cntb += 1; } } iota(oa.begin(), oa.end(), 0), iota(ob.begin(), ob.end(), 0); sort(oa.begin(), oa.end(), [&a](int i, int j) { return a[i] < a[j]; }); sort(ob.begin(), ob.end(), [&](int i, int j) { if (b[i] == -1) return false; if (b[j] == -1) return true; return b[i] < b[j]; }); const db inf = 1e12; auto solve = [&](int mx) -> db { for (int i = 0; i <= n; ++i) { for (int j = 0; j <= mx; ++j) { for (int k = 0; k <= K - j; ++k) { dp[i][j][k] = inf; } } } dp[0][0][0] = 0; for (int i = 1; i <= n; ++i) { //don't take for (int j = 0; j <= mx; ++j) { for (int k = 0; k <= K - j; ++k) { dp[i][j][k] = dp[i - 1][j][k]; } } //take a int idx = ob[i - 1]; for (int j = 0; j <= min(i, mx); ++j) { for (int k = 1; k <= min(i, K) - j; ++k) { dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k - 1] + a[idx] / db(mx + 1)); } } if (b[idx] != -1) { for (int j = 1; j <= min(i, mx); ++j) { for (int k = 0; k <= min(i, K) - j; ++k) { dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j - 1][k] + b[idx] / db(j)); } } } } return dp[n][mx][K - mx]; }; db ans = inf; for (int cnt = 0; cnt <= min(K, cntb); ++cnt) { ans = min(ans, solve(cnt)); } cout << fixed << setprecision(20) << ans; 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...