Submission #940717

# Submission time Handle Problem Language Result Execution time Memory
940717 2024-03-07T14:06:26 Z TAhmed33 Let's Win the Election (JOI22_ho_t3) C++
100 / 100
512 ms 8836 KB
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
const ld inf = 1e16;
int n, k; 
const int MAXN = 525;
pair <int, int> a[MAXN];
ld pre[MAXN][MAXN];
int main () {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
    cout << fixed << setprecision(9);
    sort(a + 1, a + n + 1, [&] (pair <int, int> &x, pair <int, int> &y) {
    	if (x.second == -1) return bool(0);
        return x.second == y.second ? x.first < y.first : ((y.second == -1) || (x.second < y.second));
    });
    for (int i = 0; i < MAXN; i++) for (int j = 0; j < MAXN; j++) pre[i][j] = inf;
    for (int i = 1; i <= n; i++) {
    	vector <int> xx;
    	for (int j = i; j <= n; j++) xx.push_back(a[j].first);
    	sort(xx.begin(), xx.end());
    	int sum = 0;
    	for (int j = 0; j < (int)xx.size(); j++) {
    		sum += xx[j];
    		pre[i][j + 1] = sum; 
    	}
    	pre[i][0] = 0;
    }
    ld mn = 1e18;
    for (int sze = 0; sze <= k; sze++) {
        ld dp[n + 1][sze + 1];
        for (int j = 1; j <= sze; j++) {
            dp[0][j] = inf;
        }
        dp[0][0] = 0; 
        mn = min(mn, 1.0 * pre[1][k] / (sze + 1) + dp[0][sze]);
        for (int i = 1; i <= n; i++) {
        	for (int j = 0; j <= sze; j++) dp[i][j] = inf;
        	for (int j = 0; j <= min(sze, i); j++) {
        		if (i - j) dp[i][j] = dp[i - 1][j] + 1.0 * a[i].first / (sze + 1);
        		if (a[i].second != -1 && j) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1.0 * a[i].second / j);
        	}
        	if (k >= i) {
        		mn = min(mn, 1.0 * pre[i + 1][k - i] / (sze + 1) + dp[i][sze]);
        	}
        	if (k == i) {
        		mn = min(mn, dp[i][sze]);
        	}
        }
    }
    cout << mn << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 3 ms 4696 KB Output is correct
5 Correct 10 ms 4956 KB Output is correct
6 Correct 27 ms 5612 KB Output is correct
7 Correct 88 ms 6548 KB Output is correct
8 Correct 173 ms 7508 KB Output is correct
9 Correct 278 ms 8464 KB Output is correct
10 Correct 145 ms 7248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 3 ms 4696 KB Output is correct
5 Correct 10 ms 4956 KB Output is correct
6 Correct 27 ms 5612 KB Output is correct
7 Correct 88 ms 6548 KB Output is correct
8 Correct 173 ms 7508 KB Output is correct
9 Correct 278 ms 8464 KB Output is correct
10 Correct 145 ms 7248 KB Output is correct
11 Correct 2 ms 4696 KB Output is correct
12 Correct 61 ms 5816 KB Output is correct
13 Correct 51 ms 5716 KB Output is correct
14 Correct 39 ms 5716 KB Output is correct
15 Correct 279 ms 7388 KB Output is correct
16 Correct 206 ms 7248 KB Output is correct
17 Correct 158 ms 7420 KB Output is correct
18 Correct 502 ms 8496 KB Output is correct
19 Correct 381 ms 8592 KB Output is correct
20 Correct 287 ms 8788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 2 ms 4696 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 2 ms 4696 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4716 KB Output is correct
22 Correct 2 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4720 KB Output is correct
26 Correct 2 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 2 ms 4700 KB Output is correct
29 Correct 2 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 2 ms 4696 KB Output is correct
32 Correct 1 ms 4696 KB Output is correct
33 Correct 1 ms 4696 KB Output is correct
34 Correct 1 ms 4696 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 2 ms 4696 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 4700 KB Output is correct
9 Correct 2 ms 4700 KB Output is correct
10 Correct 1 ms 4700 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4700 KB Output is correct
14 Correct 1 ms 4700 KB Output is correct
15 Correct 1 ms 4700 KB Output is correct
16 Correct 1 ms 4700 KB Output is correct
17 Correct 1 ms 4700 KB Output is correct
18 Correct 1 ms 4696 KB Output is correct
19 Correct 1 ms 4700 KB Output is correct
20 Correct 1 ms 4700 KB Output is correct
21 Correct 1 ms 4716 KB Output is correct
22 Correct 2 ms 4700 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4720 KB Output is correct
26 Correct 2 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 2 ms 4700 KB Output is correct
29 Correct 2 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 2 ms 4696 KB Output is correct
32 Correct 1 ms 4696 KB Output is correct
33 Correct 1 ms 4696 KB Output is correct
34 Correct 1 ms 4696 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4700 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 2 ms 4700 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 2 ms 4700 KB Output is correct
44 Correct 2 ms 4760 KB Output is correct
45 Correct 3 ms 4700 KB Output is correct
46 Correct 3 ms 4952 KB Output is correct
47 Correct 4 ms 4700 KB Output is correct
48 Correct 3 ms 4700 KB Output is correct
49 Correct 4 ms 4820 KB Output is correct
50 Correct 4 ms 4700 KB Output is correct
51 Correct 5 ms 4840 KB Output is correct
52 Correct 6 ms 4700 KB Output is correct
53 Correct 4 ms 4704 KB Output is correct
54 Correct 4 ms 4708 KB Output is correct
55 Correct 3 ms 4704 KB Output is correct
56 Correct 4 ms 4696 KB Output is correct
57 Correct 4 ms 4704 KB Output is correct
58 Correct 3 ms 4856 KB Output is correct
59 Correct 4 ms 4704 KB Output is correct
60 Correct 4 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 498 ms 8468 KB Output is correct
2 Correct 492 ms 8644 KB Output is correct
3 Correct 512 ms 8532 KB Output is correct
4 Correct 496 ms 8616 KB Output is correct
5 Correct 492 ms 8460 KB Output is correct
6 Correct 502 ms 8480 KB Output is correct
7 Correct 510 ms 8836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4700 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 3 ms 4696 KB Output is correct
5 Correct 10 ms 4956 KB Output is correct
6 Correct 27 ms 5612 KB Output is correct
7 Correct 88 ms 6548 KB Output is correct
8 Correct 173 ms 7508 KB Output is correct
9 Correct 278 ms 8464 KB Output is correct
10 Correct 145 ms 7248 KB Output is correct
11 Correct 2 ms 4696 KB Output is correct
12 Correct 61 ms 5816 KB Output is correct
13 Correct 51 ms 5716 KB Output is correct
14 Correct 39 ms 5716 KB Output is correct
15 Correct 279 ms 7388 KB Output is correct
16 Correct 206 ms 7248 KB Output is correct
17 Correct 158 ms 7420 KB Output is correct
18 Correct 502 ms 8496 KB Output is correct
19 Correct 381 ms 8592 KB Output is correct
20 Correct 287 ms 8788 KB Output is correct
21 Correct 1 ms 4696 KB Output is correct
22 Correct 2 ms 4696 KB Output is correct
23 Correct 1 ms 4700 KB Output is correct
24 Correct 1 ms 4700 KB Output is correct
25 Correct 1 ms 4700 KB Output is correct
26 Correct 1 ms 4700 KB Output is correct
27 Correct 1 ms 4700 KB Output is correct
28 Correct 1 ms 4700 KB Output is correct
29 Correct 2 ms 4700 KB Output is correct
30 Correct 1 ms 4700 KB Output is correct
31 Correct 2 ms 4700 KB Output is correct
32 Correct 1 ms 4700 KB Output is correct
33 Correct 1 ms 4700 KB Output is correct
34 Correct 1 ms 4700 KB Output is correct
35 Correct 1 ms 4700 KB Output is correct
36 Correct 1 ms 4700 KB Output is correct
37 Correct 1 ms 4700 KB Output is correct
38 Correct 1 ms 4696 KB Output is correct
39 Correct 1 ms 4700 KB Output is correct
40 Correct 1 ms 4700 KB Output is correct
41 Correct 1 ms 4716 KB Output is correct
42 Correct 2 ms 4700 KB Output is correct
43 Correct 1 ms 4700 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 1 ms 4720 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 1 ms 4700 KB Output is correct
48 Correct 2 ms 4700 KB Output is correct
49 Correct 2 ms 4700 KB Output is correct
50 Correct 1 ms 4700 KB Output is correct
51 Correct 2 ms 4696 KB Output is correct
52 Correct 1 ms 4696 KB Output is correct
53 Correct 1 ms 4696 KB Output is correct
54 Correct 1 ms 4696 KB Output is correct
55 Correct 1 ms 4700 KB Output is correct
56 Correct 1 ms 4700 KB Output is correct
57 Correct 1 ms 4700 KB Output is correct
58 Correct 1 ms 4700 KB Output is correct
59 Correct 1 ms 4700 KB Output is correct
60 Correct 1 ms 4700 KB Output is correct
61 Correct 2 ms 4700 KB Output is correct
62 Correct 2 ms 4700 KB Output is correct
63 Correct 2 ms 4700 KB Output is correct
64 Correct 2 ms 4760 KB Output is correct
65 Correct 3 ms 4700 KB Output is correct
66 Correct 3 ms 4952 KB Output is correct
67 Correct 4 ms 4700 KB Output is correct
68 Correct 3 ms 4700 KB Output is correct
69 Correct 4 ms 4820 KB Output is correct
70 Correct 4 ms 4700 KB Output is correct
71 Correct 5 ms 4840 KB Output is correct
72 Correct 6 ms 4700 KB Output is correct
73 Correct 4 ms 4704 KB Output is correct
74 Correct 4 ms 4708 KB Output is correct
75 Correct 3 ms 4704 KB Output is correct
76 Correct 4 ms 4696 KB Output is correct
77 Correct 4 ms 4704 KB Output is correct
78 Correct 3 ms 4856 KB Output is correct
79 Correct 4 ms 4704 KB Output is correct
80 Correct 4 ms 4812 KB Output is correct
81 Correct 498 ms 8468 KB Output is correct
82 Correct 492 ms 8644 KB Output is correct
83 Correct 512 ms 8532 KB Output is correct
84 Correct 496 ms 8616 KB Output is correct
85 Correct 492 ms 8460 KB Output is correct
86 Correct 502 ms 8480 KB Output is correct
87 Correct 510 ms 8836 KB Output is correct
88 Correct 12 ms 4996 KB Output is correct
89 Correct 13 ms 4956 KB Output is correct
90 Correct 46 ms 5536 KB Output is correct
91 Correct 47 ms 5720 KB Output is correct
92 Correct 152 ms 6644 KB Output is correct
93 Correct 153 ms 6664 KB Output is correct
94 Correct 306 ms 7508 KB Output is correct
95 Correct 324 ms 7684 KB Output is correct
96 Correct 425 ms 8164 KB Output is correct
97 Correct 432 ms 8448 KB Output is correct
98 Correct 276 ms 7388 KB Output is correct
99 Correct 287 ms 7660 KB Output is correct
100 Correct 272 ms 7400 KB Output is correct
101 Correct 304 ms 7372 KB Output is correct
102 Correct 279 ms 7340 KB Output is correct
103 Correct 276 ms 7248 KB Output is correct
104 Correct 281 ms 7400 KB Output is correct
105 Correct 271 ms 7328 KB Output is correct