# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
804534 | 2023-08-03T09:37:19 Z | MilosMilutinovic | Let's Win the Election (JOI22_ho_t3) | C++14 | 310 ms | 4308 KB |
#include <bits/stdc++.h> using namespace std; #define ldb double const int MAX = 505; const ldb inf = (ldb) 1e9; int n, m, a[MAX], b[MAX]; int order[MAX]; ldb dp[2][MAX][MAX]; bool cmp(int i, int j) { int vi = (b[i] == -1 ? (int) 1e9 : b[i]); int vj = (b[j] == -1 ? (int) 1e9 : b[j]); return vi < vj; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d", &a[i], &b[i]); } for (int i = 1; i <= n; i++) { order[i] = i; } sort(order + 1, order + 1 + n, cmp); for (int k = 0; k < 2; k++) { for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= n; j++) { dp[k][i][j] = inf; } } } dp[0][1][0] = 0; for (int _i = 1; _i <= n; _i++) { int i = order[_i]; int f = (_i % 2), p = 1 - f; for (int j = 0; j <= n + 1; j++) { for (int k = 0; k <= n; k++) { dp[f][j][k] = dp[p][j][k]; } } if (b[i] != -1) { for (int j = 1; j <= n; j++) { for (int k = 0; k < n; k++) { dp[f][j + 1][k + 1] = min(dp[f][j + 1][k + 1], dp[p][j][k] + ((ldb) (b[i] + 0.000) / (ldb) (j + 0.000))); } } } for (int j = 1; j <= n + 1; j++) { for (int k = 0; k < n; k++) { dp[f][j][k + 1] = min(dp[f][j][k + 1], dp[p][j][k] + ((ldb) (a[i] + 0.000) / (ldb) (j + 0.000))); } } for (int j = 0; j <= n + 1; j++) { for (int k = 0; k <= n; k++) { dp[p][j][k] = dp[f][j][k]; } } } double ans = inf; for (int k = 0; k < 2; k++) { for (int i = 1; i <= n + 1; i++) { ans = min(ans, dp[k][i][m]); } } printf("%.5lf\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 304 KB | Output is correct |
5 | Correct | 195 ms | 4260 KB | Output is correct |
6 | Correct | 205 ms | 4260 KB | Output is correct |
7 | Correct | 181 ms | 4260 KB | Output is correct |
8 | Correct | 183 ms | 4264 KB | Output is correct |
9 | Correct | 205 ms | 4264 KB | Output is correct |
10 | Correct | 201 ms | 4264 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 304 KB | Output is correct |
5 | Correct | 195 ms | 4260 KB | Output is correct |
6 | Correct | 205 ms | 4260 KB | Output is correct |
7 | Correct | 181 ms | 4260 KB | Output is correct |
8 | Correct | 183 ms | 4264 KB | Output is correct |
9 | Correct | 205 ms | 4264 KB | Output is correct |
10 | Correct | 201 ms | 4264 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 310 ms | 4268 KB | Output is correct |
13 | Correct | 233 ms | 4180 KB | Output is correct |
14 | Correct | 238 ms | 4264 KB | Output is correct |
15 | Correct | 250 ms | 4264 KB | Output is correct |
16 | Correct | 258 ms | 4268 KB | Output is correct |
17 | Correct | 203 ms | 4308 KB | Output is correct |
18 | Correct | 237 ms | 4264 KB | Output is correct |
19 | Correct | 227 ms | 4264 KB | Output is correct |
20 | Correct | 187 ms | 4268 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 308 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Incorrect | 1 ms | 308 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 308 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Incorrect | 1 ms | 308 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 308 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Incorrect | 1 ms | 308 KB | Output isn't correct |
10 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 289 ms | 4260 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 0 ms | 304 KB | Output is correct |
5 | Correct | 195 ms | 4260 KB | Output is correct |
6 | Correct | 205 ms | 4260 KB | Output is correct |
7 | Correct | 181 ms | 4260 KB | Output is correct |
8 | Correct | 183 ms | 4264 KB | Output is correct |
9 | Correct | 205 ms | 4264 KB | Output is correct |
10 | Correct | 201 ms | 4264 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 310 ms | 4268 KB | Output is correct |
13 | Correct | 233 ms | 4180 KB | Output is correct |
14 | Correct | 238 ms | 4264 KB | Output is correct |
15 | Correct | 250 ms | 4264 KB | Output is correct |
16 | Correct | 258 ms | 4268 KB | Output is correct |
17 | Correct | 203 ms | 4308 KB | Output is correct |
18 | Correct | 237 ms | 4264 KB | Output is correct |
19 | Correct | 227 ms | 4264 KB | Output is correct |
20 | Correct | 187 ms | 4268 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 0 ms | 340 KB | Output is correct |
25 | Correct | 1 ms | 340 KB | Output is correct |
26 | Correct | 1 ms | 340 KB | Output is correct |
27 | Correct | 1 ms | 308 KB | Output is correct |
28 | Correct | 1 ms | 340 KB | Output is correct |
29 | Incorrect | 1 ms | 308 KB | Output isn't correct |
30 | Halted | 0 ms | 0 KB | - |