답안 #526355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526355 2022-02-14T13:13:05 Z model_code Let's Win the Election (JOI22_ho_t3) C++17
56 / 100
2500 ms 1002444 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];
double dp[509][509][509]; // (pos, total votes, cooperator)

double solve(int Goal) {
	// Initialize [1]
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			for (int k = 0; k <= N; k++) dp[i][j][k] = 1e9;
		}
	}
	
	// Dynamic Programming
	dp[0][0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= K; j++) {
			for (int k = 0; k <= 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] + 1.0 * 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] + 1.0 * X[i + 1].b / (k + 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
	double Answer = 1e9;
	for (int i = 0; i <= K; i++) {
		double ret = solve(i);
		Answer = min(Answer, ret);
	}
	
	// Step #4. Output
	printf("%.15lf\n", Answer);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 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 Execution timed out 2607 ms 1002260 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 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 Execution timed out 2607 ms 1002260 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 0 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 0 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 2124 KB Output is correct
17 Correct 1 ms 2124 KB Output is correct
18 Correct 2 ms 2124 KB Output is correct
19 Correct 1 ms 2124 KB Output is correct
20 Correct 1 ms 2124 KB Output is correct
21 Correct 2 ms 2124 KB Output is correct
22 Correct 1 ms 2124 KB Output is correct
23 Correct 1 ms 2124 KB Output is correct
24 Correct 2 ms 2124 KB Output is correct
25 Correct 1 ms 2124 KB Output is correct
26 Correct 1 ms 2124 KB Output is correct
27 Correct 2 ms 2124 KB Output is correct
28 Correct 2 ms 2124 KB Output is correct
29 Correct 1 ms 2124 KB Output is correct
30 Correct 1 ms 2076 KB Output is correct
31 Correct 1 ms 2124 KB Output is correct
32 Correct 2 ms 2124 KB Output is correct
33 Correct 1 ms 2124 KB Output is correct
34 Correct 1 ms 2124 KB Output is correct
35 Correct 2 ms 2124 KB Output is correct
36 Correct 1 ms 2124 KB Output is correct
37 Correct 1 ms 2124 KB Output is correct
38 Correct 1 ms 2240 KB Output is correct
39 Correct 1 ms 2124 KB Output is correct
40 Correct 1 ms 2124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 0 ms 588 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 1 ms 2124 KB Output is correct
17 Correct 1 ms 2124 KB Output is correct
18 Correct 2 ms 2124 KB Output is correct
19 Correct 1 ms 2124 KB Output is correct
20 Correct 1 ms 2124 KB Output is correct
21 Correct 2 ms 2124 KB Output is correct
22 Correct 1 ms 2124 KB Output is correct
23 Correct 1 ms 2124 KB Output is correct
24 Correct 2 ms 2124 KB Output is correct
25 Correct 1 ms 2124 KB Output is correct
26 Correct 1 ms 2124 KB Output is correct
27 Correct 2 ms 2124 KB Output is correct
28 Correct 2 ms 2124 KB Output is correct
29 Correct 1 ms 2124 KB Output is correct
30 Correct 1 ms 2076 KB Output is correct
31 Correct 1 ms 2124 KB Output is correct
32 Correct 2 ms 2124 KB Output is correct
33 Correct 1 ms 2124 KB Output is correct
34 Correct 1 ms 2124 KB Output is correct
35 Correct 2 ms 2124 KB Output is correct
36 Correct 1 ms 2124 KB Output is correct
37 Correct 1 ms 2124 KB Output is correct
38 Correct 1 ms 2240 KB Output is correct
39 Correct 1 ms 2124 KB Output is correct
40 Correct 1 ms 2124 KB Output is correct
41 Correct 54 ms 41292 KB Output is correct
42 Correct 48 ms 41292 KB Output is correct
43 Correct 85 ms 41356 KB Output is correct
44 Correct 86 ms 41348 KB Output is correct
45 Correct 166 ms 41364 KB Output is correct
46 Correct 170 ms 41332 KB Output is correct
47 Correct 217 ms 41312 KB Output is correct
48 Correct 223 ms 41348 KB Output is correct
49 Correct 359 ms 41360 KB Output is correct
50 Correct 362 ms 41356 KB Output is correct
51 Correct 534 ms 41820 KB Output is correct
52 Correct 537 ms 41860 KB Output is correct
53 Correct 280 ms 41356 KB Output is correct
54 Correct 252 ms 41352 KB Output is correct
55 Correct 278 ms 41356 KB Output is correct
56 Correct 278 ms 41360 KB Output is correct
57 Correct 247 ms 41292 KB Output is correct
58 Correct 232 ms 41352 KB Output is correct
59 Correct 286 ms 41356 KB Output is correct
60 Correct 228 ms 41352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2612 ms 1002444 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 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 Execution timed out 2607 ms 1002260 KB Time limit exceeded
6 Halted 0 ms 0 KB -