Submission #794830

#TimeUsernameProblemLanguageResultExecution timeMemory
794830gun_ganLet's Win the Election (JOI22_ho_t3)C++17
61 / 100
2610 ms1008548 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 505; int N, K; int a[MX], b[MX]; double dp[MX][MX][MX]; vector<pair<int, int>> v; double f(int x) { for(int i = 0; i < MX; i++) for(int j = 0; j < MX; j++) for(int k = 0; k < MX; k++) dp[i][j][k] = 1e9; dp[0][0][0] = 0; for(int i = 0; i < N; i++) { for(int j = 0; j <= N; j++) { // votes for(int k = 0; k <= N; k++) { // num of collaborator if(dp[i][j][k] == 1e9) continue; // skip dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]); // ambil vote dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + (double) v[i].second / (x + 1)); // ambil collaborator if(v[i].first != 1e9) dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k] + (double) v[i].first / (k + 1)); } } } return dp[N][K][x]; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> N >> K; int tot = 0; for(int i = 1; i <= N; i++) { cin >> a[i] >> b[i]; if(b[i] != -1) tot++; else b[i] = 1e9; v.push_back({b[i], a[i]}); } sort(v.begin(), v.end()); double ans = 1e9; int l = 0, r = min(K, tot); while(r - l > 1) { int mid = (l + r) >> 1; if(f(mid) > f(mid + 1)) l = mid; else r = mid; } cout << fixed << setprecision(15) << min(f(l), f(l + 1)) << '\n'; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:56:14: warning: unused variable 'ans' [-Wunused-variable]
   56 |       double ans = 1e9;
      |              ^~~
#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...