Submission #593697

#TimeUsernameProblemLanguageResultExecution timeMemory
593697piOOELet's Win the Election (JOI22_ho_t3)C++17
0 / 100
928 ms469428 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; const int N = 501; db dp[N][N][N]; //id, b, a db solved[N]; 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 { if (solved[mx] == 0) { for (int j = 0; j <= mx; ++j) { for (int k = 0; k <= K - j; ++k) { dp[0][j][k] = inf; } } dp[0][0][0] = 0; for (int i = 1; i <= n; ++i) { //don't take for (int j = 0; j <= min(i, mx); ++j) { for (int k = 0; k <= min(i, 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)); } } } } solved[mx] = dp[n][mx][K - mx]; } return solved[mx]; }; int r = min(K, cntb); int x = 0; for (int k = 10; k > -1; --k) { db ansL = (x >= (1 << k) ? solve(x - (1 << k)) : inf); db ans = solve(x); db ansR = (x + (1 << k) <= r ? solve(x + (1 << k)) : inf); if (ansL <= ans && ansL <= ansR) { x -= (1 << k); } else if (ansR <= ans) { x += (1 << k); } } cout << fixed << setprecision(20) << solve(x); 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...