Submission #890654

#TimeUsernameProblemLanguageResultExecution timeMemory
890654arbuzickLet's Win the Election (JOI22_ho_t3)C++17
61 / 100
2582 ms821352 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 get_ans(int n, int k, vector<double> &a, vector<pair<double, int>> &s_b, int 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 = 0; 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]); } } } 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 = inf, ans_prv = inf; for (int cnt_all = 0; cnt_all < k; ++cnt_all) { ans = min(ans, get_ans(n, k, a, s_b, cnt_all)); if (abs(ans - ans_prv) < eps) { break; } ans_prv = ans; } 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...