답안 #526419

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
526419 2022-02-14T17:54:46 Z benson1029 Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
1229 ms 994624 KB
#include<bits/stdc++.h>
using namespace std;

int n;
int k;

pair<int,int> tmp[505];
int a[505], b[505];
double dp[505][505][505]; // dp: assume chosen number, first x, number of non-chosen
vector<int> t;

bool cmp(pair<int,int> a, pair<int,int> b) {
	if(a.first == -1) a.first = 1e9;
	if(b.first == -1) b.first = 1e9;
	return a < b;
} 

int main() {
	cin >> n >> k;
	for(int i=1; i<=n; i++) {
		cin >> a[i] >> b[i];
		tmp[i] = {b[i], a[i]};
	}
	sort(tmp+1, tmp+n+1, cmp);
	for(int i=1; i<=n; i++) {
		a[i] = tmp[i].second;
		b[i] = tmp[i].first;
	}
	double ans = 1e18;
	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] = 1e18;
	for(int i=0; i<=n; i++) dp[i][0][0] = 0;
	for(int i=0; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			for(int k=0; k<=j; k++) {
				if(k<j && b[j]!=-1) {
					dp[i][j][k] = min(dp[i][j][k], dp[i][j-1][k] + (b[j] * 1.0) / (j-k));
				}
				if(k>0) {
					dp[i][j][k] = min(dp[i][j][k], dp[i][j-1][k-1] + (a[j] * 1.0) / (i+1));
				}
			}
		}
	}
	for(int i=0; i<=n; i++) {
		for(int j=0; j<=i; j++) {
			double v = dp[i-j][i][j];
			t.clear();
			for(int l=i+1; l<=n; l++) {
				t.push_back(a[l]);
			}
			sort(t.begin(), t.end());
			if(k-i > t.size()) continue;
			for(int l=0; l<k-i; l++) {
				v += (t[l] * 1.0) / (i-j + 1);
			}
			ans = min(v, ans);
		}
	}
	cout << fixed << setprecision(6) << ans << "\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:52:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |    if(k-i > t.size()) continue;
      |       ~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 689 ms 994584 KB Output is correct
6 Correct 678 ms 994396 KB Output is correct
7 Correct 701 ms 994584 KB Output is correct
8 Correct 713 ms 994624 KB Output is correct
9 Correct 772 ms 994496 KB Output is correct
10 Correct 695 ms 994500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 689 ms 994584 KB Output is correct
6 Correct 678 ms 994396 KB Output is correct
7 Correct 701 ms 994584 KB Output is correct
8 Correct 713 ms 994624 KB Output is correct
9 Correct 772 ms 994496 KB Output is correct
10 Correct 695 ms 994500 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 870 ms 994396 KB Output is correct
13 Correct 998 ms 994444 KB Output is correct
14 Correct 765 ms 994500 KB Output is correct
15 Correct 828 ms 994388 KB Output is correct
16 Correct 835 ms 994428 KB Output is correct
17 Correct 748 ms 994500 KB Output is correct
18 Correct 825 ms 994508 KB Output is correct
19 Correct 926 ms 994500 KB Output is correct
20 Correct 801 ms 994500 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 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 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 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 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 2 ms 2124 KB Output is correct
17 Correct 2 ms 2124 KB Output is correct
18 Correct 1 ms 2124 KB Output is correct
19 Correct 1 ms 2124 KB Output is correct
20 Correct 2 ms 2124 KB Output is correct
21 Correct 1 ms 2124 KB Output is correct
22 Correct 2 ms 2124 KB Output is correct
23 Correct 2 ms 2124 KB Output is correct
24 Correct 2 ms 2044 KB Output is correct
25 Correct 1 ms 2124 KB Output is correct
26 Correct 1 ms 2124 KB Output is correct
27 Correct 1 ms 2124 KB Output is correct
28 Correct 1 ms 2124 KB Output is correct
29 Correct 2 ms 2124 KB Output is correct
30 Correct 1 ms 2124 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 2 ms 2124 KB Output is correct
38 Correct 2 ms 2124 KB Output is correct
39 Correct 2 ms 2124 KB Output is correct
40 Correct 2 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 460 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 588 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 2 ms 2124 KB Output is correct
17 Correct 2 ms 2124 KB Output is correct
18 Correct 1 ms 2124 KB Output is correct
19 Correct 1 ms 2124 KB Output is correct
20 Correct 2 ms 2124 KB Output is correct
21 Correct 1 ms 2124 KB Output is correct
22 Correct 2 ms 2124 KB Output is correct
23 Correct 2 ms 2124 KB Output is correct
24 Correct 2 ms 2044 KB Output is correct
25 Correct 1 ms 2124 KB Output is correct
26 Correct 1 ms 2124 KB Output is correct
27 Correct 1 ms 2124 KB Output is correct
28 Correct 1 ms 2124 KB Output is correct
29 Correct 2 ms 2124 KB Output is correct
30 Correct 1 ms 2124 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 2 ms 2124 KB Output is correct
38 Correct 2 ms 2124 KB Output is correct
39 Correct 2 ms 2124 KB Output is correct
40 Correct 2 ms 2124 KB Output is correct
41 Correct 28 ms 41028 KB Output is correct
42 Correct 27 ms 41036 KB Output is correct
43 Correct 23 ms 40944 KB Output is correct
44 Correct 20 ms 41032 KB Output is correct
45 Correct 21 ms 40956 KB Output is correct
46 Correct 22 ms 41028 KB Output is correct
47 Correct 23 ms 40944 KB Output is correct
48 Correct 27 ms 41032 KB Output is correct
49 Correct 22 ms 40932 KB Output is correct
50 Correct 29 ms 41036 KB Output is correct
51 Correct 22 ms 40920 KB Output is correct
52 Correct 23 ms 40916 KB Output is correct
53 Correct 26 ms 40908 KB Output is correct
54 Correct 26 ms 41032 KB Output is correct
55 Correct 29 ms 40928 KB Output is correct
56 Correct 26 ms 40968 KB Output is correct
57 Correct 23 ms 40948 KB Output is correct
58 Correct 26 ms 40908 KB Output is correct
59 Correct 27 ms 41004 KB Output is correct
60 Correct 29 ms 40976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 946 ms 994408 KB Output is correct
2 Correct 1113 ms 994496 KB Output is correct
3 Correct 1012 ms 994620 KB Output is correct
4 Correct 1006 ms 994600 KB Output is correct
5 Correct 982 ms 994496 KB Output is correct
6 Correct 995 ms 994576 KB Output is correct
7 Correct 1073 ms 994500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 689 ms 994584 KB Output is correct
6 Correct 678 ms 994396 KB Output is correct
7 Correct 701 ms 994584 KB Output is correct
8 Correct 713 ms 994624 KB Output is correct
9 Correct 772 ms 994496 KB Output is correct
10 Correct 695 ms 994500 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 870 ms 994396 KB Output is correct
13 Correct 998 ms 994444 KB Output is correct
14 Correct 765 ms 994500 KB Output is correct
15 Correct 828 ms 994388 KB Output is correct
16 Correct 835 ms 994428 KB Output is correct
17 Correct 748 ms 994500 KB Output is correct
18 Correct 825 ms 994508 KB Output is correct
19 Correct 926 ms 994500 KB Output is correct
20 Correct 801 ms 994500 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Correct 1 ms 588 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 588 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 588 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 588 KB Output is correct
32 Correct 1 ms 588 KB Output is correct
33 Correct 1 ms 588 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 588 KB Output is correct
36 Correct 2 ms 2124 KB Output is correct
37 Correct 2 ms 2124 KB Output is correct
38 Correct 1 ms 2124 KB Output is correct
39 Correct 1 ms 2124 KB Output is correct
40 Correct 2 ms 2124 KB Output is correct
41 Correct 1 ms 2124 KB Output is correct
42 Correct 2 ms 2124 KB Output is correct
43 Correct 2 ms 2124 KB Output is correct
44 Correct 2 ms 2044 KB Output is correct
45 Correct 1 ms 2124 KB Output is correct
46 Correct 1 ms 2124 KB Output is correct
47 Correct 1 ms 2124 KB Output is correct
48 Correct 1 ms 2124 KB Output is correct
49 Correct 2 ms 2124 KB Output is correct
50 Correct 1 ms 2124 KB Output is correct
51 Correct 1 ms 2124 KB Output is correct
52 Correct 2 ms 2124 KB Output is correct
53 Correct 1 ms 2124 KB Output is correct
54 Correct 1 ms 2124 KB Output is correct
55 Correct 2 ms 2124 KB Output is correct
56 Correct 1 ms 2124 KB Output is correct
57 Correct 2 ms 2124 KB Output is correct
58 Correct 2 ms 2124 KB Output is correct
59 Correct 2 ms 2124 KB Output is correct
60 Correct 2 ms 2124 KB Output is correct
61 Correct 28 ms 41028 KB Output is correct
62 Correct 27 ms 41036 KB Output is correct
63 Correct 23 ms 40944 KB Output is correct
64 Correct 20 ms 41032 KB Output is correct
65 Correct 21 ms 40956 KB Output is correct
66 Correct 22 ms 41028 KB Output is correct
67 Correct 23 ms 40944 KB Output is correct
68 Correct 27 ms 41032 KB Output is correct
69 Correct 22 ms 40932 KB Output is correct
70 Correct 29 ms 41036 KB Output is correct
71 Correct 22 ms 40920 KB Output is correct
72 Correct 23 ms 40916 KB Output is correct
73 Correct 26 ms 40908 KB Output is correct
74 Correct 26 ms 41032 KB Output is correct
75 Correct 29 ms 40928 KB Output is correct
76 Correct 26 ms 40968 KB Output is correct
77 Correct 23 ms 40948 KB Output is correct
78 Correct 26 ms 40908 KB Output is correct
79 Correct 27 ms 41004 KB Output is correct
80 Correct 29 ms 40976 KB Output is correct
81 Correct 946 ms 994408 KB Output is correct
82 Correct 1113 ms 994496 KB Output is correct
83 Correct 1012 ms 994620 KB Output is correct
84 Correct 1006 ms 994600 KB Output is correct
85 Correct 982 ms 994496 KB Output is correct
86 Correct 995 ms 994576 KB Output is correct
87 Correct 1073 ms 994500 KB Output is correct
88 Correct 980 ms 994504 KB Output is correct
89 Correct 1060 ms 994496 KB Output is correct
90 Correct 1046 ms 994508 KB Output is correct
91 Correct 1229 ms 994496 KB Output is correct
92 Correct 954 ms 994496 KB Output is correct
93 Correct 1171 ms 994504 KB Output is correct
94 Correct 1131 ms 994504 KB Output is correct
95 Correct 1204 ms 994496 KB Output is correct
96 Correct 1071 ms 994500 KB Output is correct
97 Correct 1105 ms 994500 KB Output is correct
98 Correct 1159 ms 994520 KB Output is correct
99 Correct 1002 ms 994496 KB Output is correct
100 Correct 1010 ms 994496 KB Output is correct
101 Correct 1105 ms 994496 KB Output is correct
102 Correct 1070 ms 994496 KB Output is correct
103 Correct 1029 ms 994520 KB Output is correct
104 Correct 1006 ms 994496 KB Output is correct
105 Correct 1022 ms 994496 KB Output is correct