제출 #1122571

#제출 시각아이디문제언어결과실행 시간메모리
1122571LucaIlieLet's Win the Election (JOI22_ho_t3)C++20
11 / 100
2594 ms4164 KiB
#include <bits/stdc++.h> using namespace std; struct state { int a, b; }; const int MAX_N = 500; const double INF = 1e6; state states[MAX_N + 1]; double dp[2][MAX_N + 1][MAX_N + 1]; int main() { int n, k; cout << fixed << setprecision( 6 ); cin >> n >> k; for ( int i = 1; i <= n; i++ ) cin >> states[i].a >> states[i].b; sort( states + 1, states + n, []( state x, state y ) { return x.b < y.b; } ); double minCost = INF; for ( int totalB = 0; totalB <= k; totalB++ ) { bool side = 0; for ( int a = 0; a <= k; a++ ) { for ( int b = 0; a + b <= k; b++ ) dp[side][a][b] = INF; } dp[side][0][0] = 0.0; for ( int i = 1; i <= n; i++ ) { side ^= 1; for ( int a = 0; a <= k; a++ ) { for ( int b = 0; b <= k - a; b++ ) dp[side][a][b] = dp[1 - side][a][b]; } for ( int a = 0; a <= k; a++ ) { for ( int b = 0; b <= k - a; b++ ) { dp[side][a + 1][b] = min( dp[side][a + 1][b], dp[side ^ 1][a][b] + (double)states[i].a / (totalB + 1)); if ( states[i].b != -1 ) dp[side][a][b + 1] = min( dp[side][a][b + 1], dp[side ^ 1][a][b] + (double)states[i].b / (b + 1)); } } } minCost = min( minCost, dp[side][k - totalB][totalB] ); } cout << minCost << "\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...