Submission #863890

#TimeUsernameProblemLanguageResultExecution timeMemory
863890phoenix0423Let's Win the Election (JOI22_ho_t3)C++17
66 / 100
2558 ms2688 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<double, double> pll; #define fastio ios::sync_with_stdio(false), cin.tie(0) #pragma GCC optimize("Ofast") #define pb push_back #define eb emplace_back #define f first #define s second #define lowbit(x) x&-x const int maxn = 2e5 + 5; const double INF = 1e18; //enumerate number of b from 0 ... k - 1 //it is optimal to get collaboraters first then give speeches to k - #b people //for a set of collaboraters, it is optimal to sort them by increasing bs double dp[505][505]; int main(void){ fastio; int n, k; cin>>n>>k; vector<pll> a(n); for(int i = 0; i < n; i++){ cin>>a[i].f>>a[i].s; if(a[i].s == -1) a[i].s = INF; } sort(a.begin(), a.end(), [&](pll a, pll b){ return a.s < b.s || (a.s == b.s && a.f < b.f);}); double best = INF; for(int goal = 0; goal < k; goal++){ // enumerate number of collaboraters(can also tenary search) for(int i = 0; i <= n; i++) for(int j = 0; j <= goal; j++) dp[i][j] = INF; dp[0][0] = 0; for(int i = 0; i < n; i++){ for(int j = 0; j < goal; j++){ dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + a[i].f / (goal + 1)); dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + a[i].s / (j + 1)); } } for(int i = 0; i <= n; i++){ //choose k - i elements for second set vector<double> cand; for(int j = i; j < n; j++) cand.pb(a[j].f); sort(cand.begin(), cand.end()); double cur = dp[i][goal]; for(int j = 0; j < k - i; j++) cur += cand[j] / (goal + 1); best = min(best, cur); } } cout<<fixed<<setprecision(5)<<best<<"\n"; }
#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...