제출 #1122582

#제출 시각아이디문제언어결과실행 시간메모리
1122582LucaIlieLet's Win the Election (JOI22_ho_t3)C++20
16 / 100
2594 ms432 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( 15 ); 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 mask = 0; mask < (1 << n); mask++ ) { double cost = 0; int speakers = 1; vector<int> rest; bool ok = true; for ( int i = 0; i < n; i++ ) { if ( (mask >> i) & 1 ) { if ( states[i + 1].b == -1 ) ok = false; cost += (double)states[i + 1].b / speakers; speakers++; } else rest.push_back( states[i + 1].a ); } if ( speakers >= k + 1 || !ok ) continue; sort( rest.begin(), rest.end() ); for ( int i = 0; i < k - speakers + 1; i++ ) cost += (double)rest[i] / speakers; minCost = min( minCost, cost ); } cout << minCost << "\n"; /*long double minCost = INF; for ( int totalB = 0; totalB <= k; totalB++ ) { bool side = false; 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[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...