Submission #890681

#TimeUsernameProblemLanguageResultExecution timeMemory
890681arbuzickLet's Win the Election (JOI22_ho_t3)C++17
61 / 100
2575 ms918964 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; constexpr int maxn = 501, inf = 1e9 + 7; constexpr double eps = 1e-4; double dp[maxn][maxn][maxn]; double ans_vl[maxn]; double get_ans(int n, int k, vector<double> &a, vector<pair<double, int>> &s_b, int cnt_all) { if (ans_vl[cnt_all] >= 0.5) { return ans_vl[cnt_all]; } for (int i = 0; i <= n; ++i) { for (int cnt_nw = 0; cnt_nw <= i && cnt_nw <= cnt_all; ++cnt_nw) { for (int cnt_used = 0; cnt_used <= k; ++cnt_used) { dp[i][cnt_nw][cnt_used] = inf; } } } dp[0][0][0] = 0; double ans = inf; for (int i = 0; i < n; ++i) { for (int cnt_nw = 0; cnt_nw <= i && cnt_nw <= cnt_all; ++cnt_nw) { for (int cnt_used = cnt_nw; cnt_used < k; ++cnt_used) { if (s_b[i].first < 10000 && cnt_nw < cnt_all) { dp[i + 1][cnt_nw + 1][cnt_used + 1] = min(dp[i + 1][cnt_nw + 1][cnt_used + 1], dp[i][cnt_nw][cnt_used] + s_b[i].first / (cnt_nw + 1)); if (cnt_used + 1 == k && cnt_nw + 1 == cnt_all) { ans = min(ans, dp[i + 1][cnt_nw + 1][cnt_used + 1]); } } dp[i + 1][cnt_nw][cnt_used + 1] = min(dp[i + 1][cnt_nw][cnt_used + 1], dp[i][cnt_nw][cnt_used] + a[s_b[i].second] / (cnt_all + 1)); if (cnt_used + 1 == k && cnt_nw == cnt_all) { ans = min(ans, dp[i + 1][cnt_nw][cnt_used + 1]); } dp[i + 1][cnt_nw][cnt_used] = min(dp[i + 1][cnt_nw][cnt_used], dp[i][cnt_nw][cnt_used]); } } } ans_vl[cnt_all] = ans; return ans; } void solve() { int n, k; cin >> n >> k; vector<double> a(n), b(n); vector<pair<double, int>> s_b; for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i]; if (b[i] > 0) { s_b.emplace_back(b[i], i); } else { s_b.emplace_back(inf, i); } } sort(s_b.begin(), s_b.end()); double ans = get_ans(n, k, a, s_b, 0); double vl = 0; int p_prv = 0; int l = 0, r = k; while (l < r - 1) { int m1, m2; double ans1, ans2; if (l == 0 && r == k) { int aa = l + (r - l) / 2.6; int bb = l + (r - l) - (aa - l); ans1 = get_ans(n, k, a, s_b, aa); ans2 = get_ans(n, k, a, s_b, bb); m1 = aa, m2 = bb; } else { int aa = l + (r - l) / 2.6; int bb = l + (r - l) - (aa - l); if (abs(aa - p_prv) < abs(bb - p_prv)) { aa = p_prv; ans1 = vl; ans2 = get_ans(n, k, a, s_b, bb); } else { bb = p_prv; ans2 = vl; ans1 = get_ans(n, k, a, s_b, aa); } m1 = aa, m2 = bb; } if (m1 == l || m2 == l || m1 == r || m2 == r) { break; } ans = min(ans, min(ans1, ans2)); if (ans1 >= ans2) { l = m1; vl = ans2; p_prv = m2; } else { r = m2; vl = ans1; p_prv = m1; } } for (int i = l + 1; i < r; ++i) { ans = min(ans, get_ans(n, k, a, s_b, i)); } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.precision(25); cout << fixed; int t = 1; // cin >> t; while (t--) { solve(); } 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...