Submission #988594

#TimeUsernameProblemLanguageResultExecution timeMemory
988594_callmelucianLet's Win the Election (JOI22_ho_t3)C++14
100 / 100
144 ms2640 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pl; typedef pair<int,int> pii; typedef tuple<int,int,int> tt; #define all(a) a.begin(), a.end() #define filter(a) a.erase(unique(all(a)), a.end()) const double INF = 1e9; double dp[505][505]; struct P { int norm, col; P() : norm(0), col(0) {} P (int a, int b) : norm(a), col(b) {} friend istream& operator >> (istream &inp, P &cur) { inp >> cur.norm >> cur.col; return inp; } bool operator < (const P &o) const { if (col == o.col || col == -1) return 0; if (o.col == -1) return 1; return col < o.col; } } a[505]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); for (int i = 0; i <= n; i++) for (int j = 0; j <= k; j++) dp[i][j] = INF; double ans = INF; for (int cntNorm = 0; cntNorm <= k; cntNorm++) { int collab = k - cntNorm; dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= min(i, cntNorm); j++) { //dp[i][j] = dp[i - 1][j]; if (j && dp[i - 1][j - 1] != INF) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + double(a[i].norm) / double(collab + 1)); if (i - j <= collab && dp[i - 1][j] != INF && a[i].col != -1) dp[i][j] = min(dp[i][j], dp[i - 1][j] + double(a[i].col) / double(i - j)); if (i - j > collab) dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } //cout << cntNorm << " " << dp[n][cntNorm] << "\n"; ans = min(ans, dp[n][cntNorm]); for (int i = 1; i <= n; i++) for (int j = 0; j <= min(i, cntNorm); j++) dp[i][j] = INF; } cout << fixed << setprecision(9) << 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...