답안 #526350

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526350 2022-02-14T13:09:15 Z model_code Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
1249 ms 503500 KB
#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];
long long dp[509][509][509]; // (pos, total votes, cooperator)
long long CONST = 1000000000;

long long solve(int Goal) {
	// Initialize [1]
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= min(i, K); j++) {
			if (i == j) {
				for (int k = 0; k <= min(j, Goal); k++) dp[i][j][k] = (1LL << 60);
			}
			else {
				dp[i][j][Goal] = (1LL << 60);
			}
		}
	}
	
	// Dynamic Programming
	dp[0][0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = max(0, K - N + i); j <= min(i, K); j++) {
			if (i == j) {
				for (int k = max(0, Goal - N + i); k <= min(j, Goal); k++) {
					dp[i + 1][j + 0][k + 0] = min(dp[i + 1][j + 0][k + 0], dp[i][j][k]);
					dp[i + 1][j + 1][k + 0] = min(dp[i + 1][j + 1][k + 0], dp[i][j][k] + CONST * X[i + 1].a / (Goal + 1));
					dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k] + CONST * X[i + 1].b / (k + 1));
				}
			}
			else {
				dp[i + 1][j + 0][Goal] = min(dp[i + 1][j + 0][Goal], dp[i][j][Goal]);
				dp[i + 1][j + 1][Goal] = min(dp[i + 1][j + 1][Goal], dp[i][j][Goal] + CONST * X[i + 1].a / (Goal + 1));
			}
		}
	}
	
	// Return Value
	return dp[N][K][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
	long long Answer = (1LL << 60);
	for (int i = 0; i <= K; i++) {
		long long ret = solve(i);
		Answer = min(Answer, ret);
	}
	
	// Step #4. Output
	printf("%lld.%09lld\n", Answer / CONST, Answer % CONST);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 616 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 60 ms 100732 KB Output is correct
6 Correct 210 ms 223820 KB Output is correct
7 Correct 660 ms 379208 KB Output is correct
8 Correct 1109 ms 472372 KB Output is correct
9 Correct 1211 ms 503208 KB Output is correct
10 Correct 959 ms 458764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 616 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 60 ms 100732 KB Output is correct
6 Correct 210 ms 223820 KB Output is correct
7 Correct 660 ms 379208 KB Output is correct
8 Correct 1109 ms 472372 KB Output is correct
9 Correct 1211 ms 503208 KB Output is correct
10 Correct 959 ms 458764 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 268 ms 259968 KB Output is correct
13 Correct 289 ms 259924 KB Output is correct
14 Correct 259 ms 259876 KB Output is correct
15 Correct 1025 ms 458716 KB Output is correct
16 Correct 1002 ms 458768 KB Output is correct
17 Correct 1008 ms 458760 KB Output is correct
18 Correct 1177 ms 503256 KB Output is correct
19 Correct 1193 ms 503500 KB Output is correct
20 Correct 1192 ms 503468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 0 ms 716 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 1 ms 1100 KB Output is correct
21 Correct 1 ms 1228 KB Output is correct
22 Correct 1 ms 1228 KB Output is correct
23 Correct 1 ms 1228 KB Output is correct
24 Correct 1 ms 1228 KB Output is correct
25 Correct 1 ms 1228 KB Output is correct
26 Correct 2 ms 1228 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 1228 KB Output is correct
29 Correct 1 ms 1100 KB Output is correct
30 Correct 1 ms 1228 KB Output is correct
31 Correct 1 ms 1228 KB Output is correct
32 Correct 1 ms 1228 KB Output is correct
33 Correct 1 ms 1100 KB Output is correct
34 Correct 1 ms 1228 KB Output is correct
35 Correct 1 ms 1228 KB Output is correct
36 Correct 1 ms 1100 KB Output is correct
37 Correct 1 ms 1228 KB Output is correct
38 Correct 1 ms 1100 KB Output is correct
39 Correct 1 ms 1228 KB Output is correct
40 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 0 ms 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 0 ms 460 KB Output is correct
12 Correct 0 ms 460 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 0 ms 716 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 1 ms 1100 KB Output is correct
21 Correct 1 ms 1228 KB Output is correct
22 Correct 1 ms 1228 KB Output is correct
23 Correct 1 ms 1228 KB Output is correct
24 Correct 1 ms 1228 KB Output is correct
25 Correct 1 ms 1228 KB Output is correct
26 Correct 2 ms 1228 KB Output is correct
27 Correct 1 ms 1100 KB Output is correct
28 Correct 1 ms 1228 KB Output is correct
29 Correct 1 ms 1100 KB Output is correct
30 Correct 1 ms 1228 KB Output is correct
31 Correct 1 ms 1228 KB Output is correct
32 Correct 1 ms 1228 KB Output is correct
33 Correct 1 ms 1100 KB Output is correct
34 Correct 1 ms 1228 KB Output is correct
35 Correct 1 ms 1228 KB Output is correct
36 Correct 1 ms 1100 KB Output is correct
37 Correct 1 ms 1228 KB Output is correct
38 Correct 1 ms 1100 KB Output is correct
39 Correct 1 ms 1228 KB Output is correct
40 Correct 1 ms 1100 KB Output is correct
41 Correct 4 ms 6988 KB Output is correct
42 Correct 3 ms 6988 KB Output is correct
43 Correct 6 ms 11468 KB Output is correct
44 Correct 6 ms 11468 KB Output is correct
45 Correct 10 ms 16324 KB Output is correct
46 Correct 11 ms 16312 KB Output is correct
47 Correct 13 ms 18776 KB Output is correct
48 Correct 13 ms 18796 KB Output is correct
49 Correct 15 ms 20372 KB Output is correct
50 Correct 17 ms 20364 KB Output is correct
51 Correct 15 ms 21228 KB Output is correct
52 Correct 16 ms 21196 KB Output is correct
53 Correct 14 ms 18756 KB Output is correct
54 Correct 13 ms 18812 KB Output is correct
55 Correct 13 ms 18796 KB Output is correct
56 Correct 14 ms 18828 KB Output is correct
57 Correct 15 ms 18796 KB Output is correct
58 Correct 13 ms 18836 KB Output is correct
59 Correct 17 ms 18848 KB Output is correct
60 Correct 14 ms 18740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1148 ms 503476 KB Output is correct
2 Correct 1174 ms 503480 KB Output is correct
3 Correct 1155 ms 503320 KB Output is correct
4 Correct 1148 ms 503396 KB Output is correct
5 Correct 1249 ms 503372 KB Output is correct
6 Correct 1191 ms 503388 KB Output is correct
7 Correct 1198 ms 503340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 616 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 60 ms 100732 KB Output is correct
6 Correct 210 ms 223820 KB Output is correct
7 Correct 660 ms 379208 KB Output is correct
8 Correct 1109 ms 472372 KB Output is correct
9 Correct 1211 ms 503208 KB Output is correct
10 Correct 959 ms 458764 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 268 ms 259968 KB Output is correct
13 Correct 289 ms 259924 KB Output is correct
14 Correct 259 ms 259876 KB Output is correct
15 Correct 1025 ms 458716 KB Output is correct
16 Correct 1002 ms 458768 KB Output is correct
17 Correct 1008 ms 458760 KB Output is correct
18 Correct 1177 ms 503256 KB Output is correct
19 Correct 1193 ms 503500 KB Output is correct
20 Correct 1192 ms 503468 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 460 KB Output is correct
25 Correct 0 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 0 ms 460 KB Output is correct
31 Correct 0 ms 460 KB Output is correct
32 Correct 0 ms 460 KB Output is correct
33 Correct 0 ms 460 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 460 KB Output is correct
36 Correct 0 ms 716 KB Output is correct
37 Correct 1 ms 972 KB Output is correct
38 Correct 1 ms 972 KB Output is correct
39 Correct 1 ms 1100 KB Output is correct
40 Correct 1 ms 1100 KB Output is correct
41 Correct 1 ms 1228 KB Output is correct
42 Correct 1 ms 1228 KB Output is correct
43 Correct 1 ms 1228 KB Output is correct
44 Correct 1 ms 1228 KB Output is correct
45 Correct 1 ms 1228 KB Output is correct
46 Correct 2 ms 1228 KB Output is correct
47 Correct 1 ms 1100 KB Output is correct
48 Correct 1 ms 1228 KB Output is correct
49 Correct 1 ms 1100 KB Output is correct
50 Correct 1 ms 1228 KB Output is correct
51 Correct 1 ms 1228 KB Output is correct
52 Correct 1 ms 1228 KB Output is correct
53 Correct 1 ms 1100 KB Output is correct
54 Correct 1 ms 1228 KB Output is correct
55 Correct 1 ms 1228 KB Output is correct
56 Correct 1 ms 1100 KB Output is correct
57 Correct 1 ms 1228 KB Output is correct
58 Correct 1 ms 1100 KB Output is correct
59 Correct 1 ms 1228 KB Output is correct
60 Correct 1 ms 1100 KB Output is correct
61 Correct 4 ms 6988 KB Output is correct
62 Correct 3 ms 6988 KB Output is correct
63 Correct 6 ms 11468 KB Output is correct
64 Correct 6 ms 11468 KB Output is correct
65 Correct 10 ms 16324 KB Output is correct
66 Correct 11 ms 16312 KB Output is correct
67 Correct 13 ms 18776 KB Output is correct
68 Correct 13 ms 18796 KB Output is correct
69 Correct 15 ms 20372 KB Output is correct
70 Correct 17 ms 20364 KB Output is correct
71 Correct 15 ms 21228 KB Output is correct
72 Correct 16 ms 21196 KB Output is correct
73 Correct 14 ms 18756 KB Output is correct
74 Correct 13 ms 18812 KB Output is correct
75 Correct 13 ms 18796 KB Output is correct
76 Correct 14 ms 18828 KB Output is correct
77 Correct 15 ms 18796 KB Output is correct
78 Correct 13 ms 18836 KB Output is correct
79 Correct 17 ms 18848 KB Output is correct
80 Correct 14 ms 18740 KB Output is correct
81 Correct 1148 ms 503476 KB Output is correct
82 Correct 1174 ms 503480 KB Output is correct
83 Correct 1155 ms 503320 KB Output is correct
84 Correct 1148 ms 503396 KB Output is correct
85 Correct 1249 ms 503372 KB Output is correct
86 Correct 1191 ms 503388 KB Output is correct
87 Correct 1198 ms 503340 KB Output is correct
88 Correct 65 ms 100720 KB Output is correct
89 Correct 60 ms 100740 KB Output is correct
90 Correct 213 ms 223872 KB Output is correct
91 Correct 223 ms 223872 KB Output is correct
92 Correct 607 ms 379188 KB Output is correct
93 Correct 618 ms 379228 KB Output is correct
94 Correct 1022 ms 472356 KB Output is correct
95 Correct 1060 ms 472364 KB Output is correct
96 Correct 1205 ms 498388 KB Output is correct
97 Correct 1233 ms 498420 KB Output is correct
98 Correct 969 ms 458676 KB Output is correct
99 Correct 1055 ms 458704 KB Output is correct
100 Correct 1129 ms 458780 KB Output is correct
101 Correct 1061 ms 458732 KB Output is correct
102 Correct 1113 ms 458828 KB Output is correct
103 Correct 1027 ms 458772 KB Output is correct
104 Correct 991 ms 458696 KB Output is correct
105 Correct 998 ms 458764 KB Output is correct