제출 #1264531

#제출 시각아이디문제언어결과실행 시간메모리
1264531kustov_vadim_533Let's Win the Election (JOI22_ho_t3)C++20
0 / 100
2591 ms997648 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define len(v) (int)((v).size()) const int inf = 1e9; inline void solve(){ int n, k; cin >> n >> k; vector<pair<ll, ll>> a(n); for (int i = 0; i < n; ++i){ cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end(), [&](pair<int, int> p1, pair<int, int> p2){ if (p1.second == -1 && p2.second == -1) return false; if (p1.second == -1 || p2.second == -1) return p1.second != -1; return p1.second < p2.second; }); auto calc = [&](int l){ vector<vector<vector<ld>>> dp(n + 1, vector<vector<ld>>(l + 1, vector<ld>(k + 1, 1e100))); dp[0][0][0] = 0; for (int i = 0; i < n; ++i){ for (int j = 0; j <= l; ++j){ for (int f = 0; f <= k; ++f){ dp[i + 1][j][f] = dp[i][j][f]; } } if (a[i].second != -1){ for (int j = 0; j < l; ++j){ for (int f = 0; f < k; ++f){ dp[i + 1][j + 1][f + 1] = min(dp[i + 1][j + 1][f + 1], dp[i][j][f] + a[i].second / (ld)(j + 1)); } } } for (int j = 0; j <= l; ++j){ for (int f = 0; f < k; ++f){ dp[i + 1][j][f + 1] = min(dp[i + 1][j][f + 1], dp[i][j][f] + a[i].first / (ld)(l + 1)); } } } return dp[n][l][k]; }; int li = 0, ri = n; while (ri - li > 2){ int mi = (li + ri) / 2; ld ans1 = calc(mi); ld ans2 = calc(mi + 1); if (ans2 > ans1){ li = mi; } else{ ri = mi; } } ld ans = 1e100; for (int i = -5; i < 5; ++i){ ans = min(ans, calc(max(min(li - i, n), 0))); } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.precision(60); int t = 1; // cin >> t; while (t--) { solve(); } }
#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...