답안 #743665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
743665 2023-05-17T16:17:24 Z ethening Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
521 ms 4784 KB
#include "bits/stdc++.h"
#include <functional>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, k;
	cin >> n >> k;
	vector<pii> pl(n + 5);
	for (int i = 1; i <= n; i++) {
		cin >> pl[i].first >> pl[i].second;
		if (pl[i].second == -1) pl[i].second = 1e9;
	}
	sort(pl.begin() + 1, pl.begin() + n + 1, [](pii& u, pii& v) {
		if (u.second == v.second) return u.first < v.first;
		else return u.second < v.second;
	});

	// suffix[i][j] = min time cost to get j region in [i, n]
	vector<vector<ll>> suffix(n + 5, vector<ll>(k + 5, 1e9));
	for (int i = n; i >= 1; i--) {
		for (int j = 0; j <= k; j++) {
			if (j > n - i + 1) break; // j > no. of region in [i, n]
			if (i == n) {
				if (j == 0) suffix[i][j] = 0;
				else if (j == 1) suffix[i][j] = pl[i].first;
			}
			else {
				suffix[i][j] = suffix[i + 1][j];
				if (j > 0) suffix[i][j] = min(suffix[i][j], suffix[i + 1][j - 1] + pl[i].first);
			}
		}
	}

	double ans = 1e16;
	for (int coop = 0; coop <= k; coop++) {
		// cout << "###" << coop << endl;

		// assume will get coop coop-er at the end
		// dp[i][j] = in [1, i], the actual min cost to get j coop-er and (i - j) no-coop region
		vector<vector<double>> dp(n + 5, vector<double>(k + 5, 1e16));
		for (int i = 0; i <= k; i++) {
			for (int j = 0; j <= min(coop, i); j++) {
				if (i == 0) {
					// miss out the case that no coop-er is needed.
					dp[i][j] = 0;
				}
				else if (i == 1) {
					if (j == 0) dp[i][j] = pl[i].first / (coop + 1.0);
					if (j == 1 && pl[i].second != 1e9) dp[i][j] = pl[i].second;
				}
				else {
					// not choose i as a coop-er
					dp[i][j] = min(dp[i][j], dp[i - 1][j] + pl[i].first / (coop + 1.0));
					// choosing i as a coop-er
					if (j > 0 && pl[i].second != 1e9) {
						dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + pl[i].second / (j - 1 + 1.0));
					}
				}
				// cout << i << " " << j << " " << dp[i][j] << endl;
				if (j == coop) {
					// cout << "@" << i << " " << j << " " << dp[i][j] << " $ " << k - i << " " << suffix[i + 1][k - i] << " " << dp[i][j] + suffix[i + 1][k - i] / (coop + 1.0) << "\n";
					if (i < k) {
						ans = min(ans, dp[i][j] + suffix[i + 1][k - i] / (coop + 1.0));
					}
					else {
						ans = min(ans, dp[i][j]);
					}
				}
			}
		}
	}
	cout << fixed << setprecision(9) << ans << "\n";
}
# 결과 실행 시간 메모리 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 4 ms 788 KB Output is correct
6 Correct 22 ms 1388 KB Output is correct
7 Correct 93 ms 2368 KB Output is correct
8 Correct 229 ms 3644 KB Output is correct
9 Correct 437 ms 4548 KB Output is correct
10 Correct 187 ms 3156 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 788 KB Output is correct
6 Correct 22 ms 1388 KB Output is correct
7 Correct 93 ms 2368 KB Output is correct
8 Correct 229 ms 3644 KB Output is correct
9 Correct 437 ms 4548 KB Output is correct
10 Correct 187 ms 3156 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 32 ms 1584 KB Output is correct
13 Correct 32 ms 1580 KB Output is correct
14 Correct 33 ms 1580 KB Output is correct
15 Correct 203 ms 3400 KB Output is correct
16 Correct 208 ms 3448 KB Output is correct
17 Correct 188 ms 3164 KB Output is correct
18 Correct 521 ms 4552 KB Output is correct
19 Correct 443 ms 4664 KB Output is correct
20 Correct 460 ms 4784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 212 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 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 212 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 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 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 212 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 320 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 212 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 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 320 KB Output is correct
25 Correct 1 ms 212 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 212 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 320 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 320 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 316 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 316 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 2 ms 444 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 3 ms 452 KB Output is correct
52 Correct 3 ms 468 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 2 ms 340 KB Output is correct
59 Correct 2 ms 340 KB Output is correct
60 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 469 ms 4532 KB Output is correct
2 Correct 475 ms 4540 KB Output is correct
3 Correct 480 ms 4512 KB Output is correct
4 Correct 475 ms 4528 KB Output is correct
5 Correct 463 ms 4444 KB Output is correct
6 Correct 474 ms 4576 KB Output is correct
7 Correct 521 ms 4668 KB Output is correct
# 결과 실행 시간 메모리 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 4 ms 788 KB Output is correct
6 Correct 22 ms 1388 KB Output is correct
7 Correct 93 ms 2368 KB Output is correct
8 Correct 229 ms 3644 KB Output is correct
9 Correct 437 ms 4548 KB Output is correct
10 Correct 187 ms 3156 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 32 ms 1584 KB Output is correct
13 Correct 32 ms 1580 KB Output is correct
14 Correct 33 ms 1580 KB Output is correct
15 Correct 203 ms 3400 KB Output is correct
16 Correct 208 ms 3448 KB Output is correct
17 Correct 188 ms 3164 KB Output is correct
18 Correct 521 ms 4552 KB Output is correct
19 Correct 443 ms 4664 KB Output is correct
20 Correct 460 ms 4784 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 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 212 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 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 316 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 320 KB Output is correct
40 Correct 1 ms 316 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 320 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 1 ms 212 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 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 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 212 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 320 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 320 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 316 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 316 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 2 ms 444 KB Output is correct
70 Correct 2 ms 468 KB Output is correct
71 Correct 3 ms 452 KB Output is correct
72 Correct 3 ms 468 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 2 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 2 ms 340 KB Output is correct
79 Correct 2 ms 340 KB Output is correct
80 Correct 2 ms 468 KB Output is correct
81 Correct 469 ms 4532 KB Output is correct
82 Correct 475 ms 4540 KB Output is correct
83 Correct 480 ms 4512 KB Output is correct
84 Correct 475 ms 4528 KB Output is correct
85 Correct 463 ms 4444 KB Output is correct
86 Correct 474 ms 4576 KB Output is correct
87 Correct 521 ms 4668 KB Output is correct
88 Correct 4 ms 780 KB Output is correct
89 Correct 5 ms 788 KB Output is correct
90 Correct 24 ms 1396 KB Output is correct
91 Correct 24 ms 1392 KB Output is correct
92 Correct 101 ms 2372 KB Output is correct
93 Correct 100 ms 2624 KB Output is correct
94 Correct 264 ms 3584 KB Output is correct
95 Correct 268 ms 3360 KB Output is correct
96 Correct 396 ms 3988 KB Output is correct
97 Correct 381 ms 3956 KB Output is correct
98 Correct 235 ms 3164 KB Output is correct
99 Correct 216 ms 3156 KB Output is correct
100 Correct 208 ms 3428 KB Output is correct
101 Correct 213 ms 3372 KB Output is correct
102 Correct 216 ms 3164 KB Output is correct
103 Correct 198 ms 3412 KB Output is correct
104 Correct 205 ms 3420 KB Output is correct
105 Correct 208 ms 3272 KB Output is correct