제출 #1122585

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