Submission #890648

#TimeUsernameProblemLanguageResultExecution timeMemory
890648arbuzickLet's Win the Election (JOI22_ho_t3)C++17
56 / 100
2896 ms1048576 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; constexpr int maxn = 101, inf = 1e9 + 7; double dp[maxn][maxn][maxn][maxn]; 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()); for (int i = 0; i <= n; ++i) { for (int cnt_all = 0; cnt_all < k; ++cnt_all) { 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_all][cnt_nw][cnt_used] = inf; } } } } for (int cnt_all = 0; cnt_all < k; ++cnt_all) { dp[0][cnt_all][0][0] = 0; } double ans = inf; for (int i = 0; i < n; ++i) { for (int cnt_all = 0; cnt_all < k; ++cnt_all) { 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_all][cnt_nw + 1][cnt_used + 1] = min(dp[i + 1][cnt_all][cnt_nw + 1][cnt_used + 1], dp[i][cnt_all][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_all][cnt_nw + 1][cnt_used + 1]); } } dp[i + 1][cnt_all][cnt_nw][cnt_used + 1] = min(dp[i + 1][cnt_all][cnt_nw][cnt_used + 1], dp[i][cnt_all][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_all][cnt_nw][cnt_used + 1]); } dp[i + 1][cnt_all][cnt_nw][cnt_used] = min(dp[i + 1][cnt_all][cnt_nw][cnt_used], dp[i][cnt_all][cnt_nw][cnt_used]); } } } } 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...