Submission #529452

#TimeUsernameProblemLanguageResultExecution timeMemory
529452wiwihoLet's Win the Election (JOI22_ho_t3)C++14
61 / 100
2594 ms3288 KiB
#include <bits/stdc++.h> #define iter(a) a.begin(), a.end() #define mp make_pair #define F first #define S second #define eb emplace_back #define lsort(a) sort(iter(a)) #define gsort(a) sort(iter(a), greater<>()) using namespace std; typedef long long ll; typedef long double ld; using pii = pair<int, int>; ll iceil(ll a, ll b){ return (a + b - 1) / b; } int n, k; vector<int> a, b; vector<ld> tans; ld calc(int cnt){ if(tans[cnt] != 1e99) return tans[cnt]; vector<vector<ld>> dp(cnt + 1, vector<ld>(k + 1, 1e87)); dp[0][0] = 0; for(int i = 1; i <= n; i++){ for(int c1 = cnt; c1 >= 0; c1--){ for(int c2 = k; c2 >= 0; c2--){ if(dp[c1][c2] == 1e87) continue; if(c1 < cnt && b[i] != -1) dp[c1 + 1][c2] = min(dp[c1 + 1][c2], dp[c1][c2] + (ld)b[i] / (c1 + 1)); if(c2 < k) dp[c1][c2 + 1] = min(dp[c1][c2 + 1], dp[c1][c2] + (ld)a[i] / (cnt + 1)); } } } //cerr << "calc " << cnt << " " << dp[cnt][k - cnt] << "\n"; tans[cnt] = dp[cnt][k - cnt]; return dp[cnt][k - cnt]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; a.resize(n + 1); b.resize(n + 1); tans.resize(k + 1, 1e99); vector<pii> tmp(n + 1); int c = 0; for(int i = 1; i <= n; i++){ cin >> tmp[i].F >> tmp[i].S; if(tmp[i].S != -1) c++; } sort(tmp.begin() + 1, tmp.end(), [&](pii a, pii b){ return a.S < b.S; }); for(int i = 1; i <= n; i++) a[i] = tmp[i].F, b[i] = tmp[i].S; int l = 0, r = c; while(l < r){ int mid = (l + r) / 2; if(calc(mid) >= calc(mid + 1)) l = mid + 1; else r = mid; } cout << fixed << setprecision(20) << calc(l) << "\n"; 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...