Submission #1122588

#TimeUsernameProblemLanguageResultExecution timeMemory
1122588LucaIlieLet's Win the Election (JOI22_ho_t3)C++20
100 / 100
1627 ms4232 KiB
#include <bits/stdc++.h> using namespace std; struct state { int a, b; }; const int MAX_N = 500; const double INF = 1e6; int n, k; state states[MAX_N + 1]; double dp[2][MAX_N + 1][MAX_N + 1]; double solve( int 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 - totalB; a++ ) { for ( int b = 0; a + b <= k && b <= totalB; 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] + (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] + (double)states[i].b / (b + 1)); } } } return dp[side][k - totalB][totalB]; } int main() { cin >> n >> k; for ( int i = 1; i <= n; i++ ) cin >> states[i].a >> states[i].b; cout << fixed << setprecision( 6 ); sort( states + 1, states + 1 + n, []( state x, state y ) { return x.b < y.b; } ); int l = 0, r = k + 1; while ( r - l > 1 ) { int mid = (l + r) / 2; if ( solve( mid ) < solve( mid - 1 ) ) l = mid; else r = mid; } cout << solve( l ) << "\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...