Submission #700497

# Submission time Handle Problem Language Result Execution time Memory
700497 2023-02-19T07:05:20 Z PenguinsAreCute Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
488 ms 2276 KB
#include <bits/stdc++.h>
using namespace std;
#define INFTY 1000000069
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == -1) return false;
    if(b.first == -1) return true;
    return a < b;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N, K; cin >> N >> K; int A[N], B[N]; pair<int, int> data[N];
    for(int i = 0; i < N; i++) {cin >> data[i].second >> data[i].first;}
    sort(data, data + N, comp);
    for(int i = 0; i < N; i++) {
        A[i] = data[i].second;
        B[i] = data[i].first;
    }
    float mn = INFTY;
    float dp[N + 1][K + 1][2];
    for(int i = 0; i <= N; i++) for(int j = 0; j <= K; j++) for(int k = 0; k < 2; k++) dp[i][j][k] = INFTY;
    for(int g = 0; g <= K; g++) {
        dp[0][0][0] = 0; if(g == 0) dp[0][0][1] = 0;
        for(int i = 1; i <= N; i++) for(int j = 0; j <= K; j++) {
            if(i - j >= 0 && i - j <= g) {
                if(i - j == g) dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][1]);
                if(j > 0) {
                    dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][0] + A[i - 1] / (float)(g + 1));
                }
                if(i - j > 0 && B[i - 1] != -1) {
                    dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0] + B[i - 1] / (float)(i - j));
                }
            }
            if(g + j <= i) {
                dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1]);
                if(j > 0) {
                    dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j - 1][1] + A[i - 1] / (float)(g + 1));
                }
                if(B[i - 1] != -1 && g + j == i) {
                    dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + B[i - 1] / (float)g);
                }
            }
        }
        mn = min(mn, dp[N][K - g][1]);
        for(int i = 0; i <= N; i++) for(int j = 0; j <= K; j++) {
            dp[i][j][0] = INFTY;
            dp[i][j][1] = INFTY;
        }
    }
    cout << mn;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 28 ms 724 KB Output is correct
7 Correct 85 ms 1236 KB Output is correct
8 Correct 233 ms 1784 KB Output is correct
9 Correct 432 ms 2272 KB Output is correct
10 Correct 209 ms 1684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 28 ms 724 KB Output is correct
7 Correct 85 ms 1236 KB Output is correct
8 Correct 233 ms 1784 KB Output is correct
9 Correct 432 ms 2272 KB Output is correct
10 Correct 209 ms 1684 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 36 ms 852 KB Output is correct
13 Correct 37 ms 896 KB Output is correct
14 Correct 43 ms 900 KB Output is correct
15 Correct 219 ms 1684 KB Output is correct
16 Correct 251 ms 1620 KB Output is correct
17 Correct 222 ms 1620 KB Output is correct
18 Correct 390 ms 2272 KB Output is correct
19 Correct 488 ms 2272 KB Output is correct
20 Correct 404 ms 2272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 260 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 280 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 368 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 316 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 260 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 280 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 368 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 316 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 316 KB Output is correct
41 Correct 1 ms 324 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 320 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 3 ms 340 KB Output is correct
48 Correct 3 ms 340 KB Output is correct
49 Correct 3 ms 340 KB Output is correct
50 Correct 3 ms 340 KB Output is correct
51 Correct 6 ms 340 KB Output is correct
52 Correct 5 ms 320 KB Output is correct
53 Correct 2 ms 340 KB Output is correct
54 Correct 3 ms 340 KB Output is correct
55 Correct 3 ms 340 KB Output is correct
56 Correct 3 ms 324 KB Output is correct
57 Correct 3 ms 340 KB Output is correct
58 Correct 2 ms 340 KB Output is correct
59 Correct 3 ms 340 KB Output is correct
60 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 458 ms 2268 KB Output is correct
2 Correct 381 ms 2272 KB Output is correct
3 Correct 407 ms 2272 KB Output is correct
4 Correct 444 ms 2272 KB Output is correct
5 Correct 418 ms 2268 KB Output is correct
6 Correct 414 ms 2260 KB Output is correct
7 Correct 412 ms 2276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 6 ms 468 KB Output is correct
6 Correct 28 ms 724 KB Output is correct
7 Correct 85 ms 1236 KB Output is correct
8 Correct 233 ms 1784 KB Output is correct
9 Correct 432 ms 2272 KB Output is correct
10 Correct 209 ms 1684 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 36 ms 852 KB Output is correct
13 Correct 37 ms 896 KB Output is correct
14 Correct 43 ms 900 KB Output is correct
15 Correct 219 ms 1684 KB Output is correct
16 Correct 251 ms 1620 KB Output is correct
17 Correct 222 ms 1620 KB Output is correct
18 Correct 390 ms 2272 KB Output is correct
19 Correct 488 ms 2272 KB Output is correct
20 Correct 404 ms 2272 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 316 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 320 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 320 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 260 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 320 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 280 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 368 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 316 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 316 KB Output is correct
61 Correct 1 ms 324 KB Output is correct
62 Correct 1 ms 212 KB Output is correct
63 Correct 2 ms 340 KB Output is correct
64 Correct 2 ms 340 KB Output is correct
65 Correct 2 ms 320 KB Output is correct
66 Correct 3 ms 340 KB Output is correct
67 Correct 3 ms 340 KB Output is correct
68 Correct 3 ms 340 KB Output is correct
69 Correct 3 ms 340 KB Output is correct
70 Correct 3 ms 340 KB Output is correct
71 Correct 6 ms 340 KB Output is correct
72 Correct 5 ms 320 KB Output is correct
73 Correct 2 ms 340 KB Output is correct
74 Correct 3 ms 340 KB Output is correct
75 Correct 3 ms 340 KB Output is correct
76 Correct 3 ms 324 KB Output is correct
77 Correct 3 ms 340 KB Output is correct
78 Correct 2 ms 340 KB Output is correct
79 Correct 3 ms 340 KB Output is correct
80 Correct 3 ms 340 KB Output is correct
81 Correct 458 ms 2268 KB Output is correct
82 Correct 381 ms 2272 KB Output is correct
83 Correct 407 ms 2272 KB Output is correct
84 Correct 444 ms 2272 KB Output is correct
85 Correct 418 ms 2268 KB Output is correct
86 Correct 414 ms 2260 KB Output is correct
87 Correct 412 ms 2276 KB Output is correct
88 Correct 7 ms 468 KB Output is correct
89 Correct 7 ms 448 KB Output is correct
90 Correct 38 ms 804 KB Output is correct
91 Correct 35 ms 808 KB Output is correct
92 Correct 105 ms 1292 KB Output is correct
93 Correct 135 ms 1288 KB Output is correct
94 Correct 250 ms 1780 KB Output is correct
95 Correct 263 ms 1788 KB Output is correct
96 Correct 361 ms 2072 KB Output is correct
97 Correct 385 ms 2076 KB Output is correct
98 Correct 236 ms 1684 KB Output is correct
99 Correct 257 ms 1684 KB Output is correct
100 Correct 250 ms 1684 KB Output is correct
101 Correct 253 ms 1600 KB Output is correct
102 Correct 278 ms 1684 KB Output is correct
103 Correct 215 ms 1744 KB Output is correct
104 Correct 225 ms 1676 KB Output is correct
105 Correct 221 ms 1688 KB Output is correct