Submission #1267777

#TimeUsernameProblemLanguageResultExecution timeMemory
1267777gustavo_dLet's Win the Election (JOI22_ho_t3)C++20
67 / 100
2608 ms1010180 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double lfloat; const int MAXN = 500; const lfloat INF = 500000; int a[MAXN], b[MAXN]; pair<int, int> input[MAXN]; lfloat dp[MAXN+1][MAXN+1][MAXN+1]; bool cmp(pair<int, int> i, pair<int, int> j) { return i.second < j.second; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, K; cin >> n >> K; for (int i=0; i<n; i++) cin >> input[i].first >> input[i].second; sort(input, input+n, cmp); for (int i=0; i<n; i++) { a[i] = input[i].first; b[i] = input[i].second; // cout << a[i] << ' ' << b[i] << endl; } lfloat ans = INF; for (int c=0; c<=K; c++) { for (int k=0; k<=K; k++) { for (int j=0; j<=K-c; j++) dp[0][k][j] = INF; } dp[0][0][0] = 0; for (int i=1; i<=n; i++) { // if (c == 1) cout << "i=" << i << endl; for (int k=0; k<=c; k++) { if (K == n) { int j = i - k; dp[i][k][j] = min( ((k == 0 or b[i-1] == -1) ? INF : (dp[i-1][k-1][j] + (lfloat)b[i-1] / (lfloat)k)), (j == 0 ? INF : (dp[i-1][k][j-1] + (lfloat)a[i-1] / (1 + (lfloat)c))) ); continue; } for (int j=0; j<=K-c; j++) { dp[i][k][j] = min({ dp[i-1][k][j], ((k == 0 or b[i-1] == -1) ? INF : (dp[i-1][k-1][j] + (lfloat)b[i-1] / (lfloat)k)), (j == 0 ? INF : (dp[i-1][k][j-1] + (lfloat)a[i-1] / (1 + (lfloat)c))) }); // if (c == 1) printf("%.5Lf ", dp[i][k][j]); } // if (c == 1) printf("\n"); } // if (c == 1) printf("\n\n"); } ans = min(ans, dp[n][c][K-c]); } printf("%.5Lf", ans); 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...