제출 #1253610

#제출 시각아이디문제언어결과실행 시간메모리
1253610norman165Let's Win the Election (JOI22_ho_t3)C++20
61 / 100
2595 ms7056 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define int long long #define yes() cout << "YES\n" #define no() cout << "NO\n" using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; const int inf = 1e18; const int mod = 1e9 + 7; const int maxn = 1e6 + 10; const int mod1 = 998244353; const int mod2 = 1e18 + 1; const int mod3 = 1e9 + 9; const int mod4 = 333333333; const int mod5 = 200000; const int mod6 = 10007; const int k = 300; const int w = 1e5; const ld EPS = 1e-8; int LOG = 30; ld dp[2][510][510]; void solve() { int n, k1; cin >> n >> k1; vector<pair<ld, ld>> a(n); for (auto& i : a) { cin >> i.first >> i.second; if (i.second == -1) i.second = inf; } sort(all(a), [](pair<ld, ld> a, pair<ld, ld> b) { return a.second < b.second || (a.second == b.second && a.first < b.first); }); ld ans = inf; vector<ld> res(k1 + 1, -1); auto f = [&](int x) { if (res[x] != -1) return res[x]; for (int i = 0; i < 2; i++) { for (int j = 0; j <= x; j++) { for (int k = 0; k <= k1 - x; k++) dp[i][j][k] = inf; } } dp[0][0][0] = 0; for (int i = 1; i <= n; i++) { int i1 = (i & 1); for (int j = 0; j <= x; j++) { for (int k = 0; k <= k1 - x; k++) { dp[i1][j][k] = dp[i1 ^ 1][j][k]; ld cnt1 = j; ld cnt2 = x; if (j > 0) dp[i1][j][k] = min(dp[i1][j][k], dp[i1 ^ 1][j - 1][k] + a[i - 1].second / cnt1); if (k > 0) dp[i1][j][k] = min(dp[i1][j][k], dp[i1 ^ 1][j][k - 1] + a[i - 1].first / (cnt2 + 1)); } } } res[x] = dp[n & 1][x][k1 - x]; return res[x]; }; int l = 0; int r = k1; while (r - l > 1) { int m = (l + r) / 2; if (f(m) <= f(m + 1)) r = m; else l = m; } ans = min(ans, f(l)); if (l != k1) ans = min(ans, f(l + 1)); if (l != 0) ans = min(ans, f(l - 1)); cout << ans << "\n"; } signed main() { cout.precision(16); ios::sync_with_stdio(false); cin.tie(nullptr); 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...