Submission #526356

#TimeUsernameProblemLanguageResultExecution timeMemory
526356model_codeLet's Win the Election (JOI22_ho_t3)C++17
11 / 100
408 ms2276 KiB
#include <iostream> #include <algorithm> using namespace std; struct Election { int a, b; }; bool operator<(const Election &a1, const Election &a2) { if (a1.b < a2.b) return true; if (a1.b > a2.b) return false; if (a1.a < a2.a) return true; return false; } int N, K; Election X[509]; double dp[509][509]; // (pos, cooperator) double solve(int Goal) { // Initialize [1] for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) dp[i][j] = 1e9; } // Dynamic Programming dp[0][0] = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j <= N; j++) { if (dp[i - 1][j] > 1e8) continue; dp[i][j + 0] = min(dp[i][j + 0], dp[i - 1][j] + 1.0 * X[i].a / (Goal + 1)); if (X[i].b != -1) { dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + 1.0 * X[i].b / (j + 1)); } } } // Return Value return dp[N][Goal]; } int main() { // Step #1. Input cin >> N; cin >> K; for (int i = 1; i <= N; i++) { cin >> X[i].a >> X[i].b; if (X[i].b == -1) X[i].b = 1000000; } // Step #2. Sorting sort(X + 1, X + N + 1); // Step #3. Brute Force double Answer = 1e9; for (int i = 0; i <= K; i++) { double ret = solve(i); Answer = min(Answer, ret); } // Step #4. Output printf("%.15lf\n", Answer); 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...