답안 #747163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747163 2023-05-23T19:06:31 Z tch1cherin Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
1526 ms 4808 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long> A(n), B(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i] >> B[i];
    B[i] = (B[i] == -1 ? 1000000000 : B[i]);
  }
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  sort(order.begin(), order.end(), [&](int i, int j) {
    return (B[i] == B[j] ? A[i] > A[j] : B[i] < B[j]);
  });
  long double ans = 1e9;
  for (int m = 0; m <= k; m++) {
    vector dp(n + 1, vector<long double>(m + 1, 1e9));
    dp[0][0] = 0;   
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= i && j <= m; j++) {
        if (j + 1 <= m) {
          dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + (long double)B[order[i]] / (j + 1)); 
        }
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (long double)A[order[i]] / (m + 1));
      }
    }
    for (int p = m; p <= n; p++) {
      vector<long long> C;
      for (int i = p; i < n; i++) {
        C.push_back(A[order[i]]);
      }
      sort(C.begin(), C.end());
      if ((int)C.size() < k - p) {
        break; 
      }
      long double res = dp[p][m];
      for (int i = 0; i < k - p; i++) {
        res += (long double)C[i] / (m + 1);
      }
      ans = min(ans, res);
    }
  }
  cout << fixed << setprecision(9) << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 82 ms 832 KB Output is correct
6 Correct 207 ms 1560 KB Output is correct
7 Correct 450 ms 2536 KB Output is correct
8 Correct 730 ms 3668 KB Output is correct
9 Correct 1058 ms 4624 KB Output is correct
10 Correct 606 ms 3384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 82 ms 832 KB Output is correct
6 Correct 207 ms 1560 KB Output is correct
7 Correct 450 ms 2536 KB Output is correct
8 Correct 730 ms 3668 KB Output is correct
9 Correct 1058 ms 4624 KB Output is correct
10 Correct 606 ms 3384 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 269 ms 1888 KB Output is correct
13 Correct 356 ms 1768 KB Output is correct
14 Correct 267 ms 1840 KB Output is correct
15 Correct 682 ms 3516 KB Output is correct
16 Correct 775 ms 3444 KB Output is correct
17 Correct 663 ms 3564 KB Output is correct
18 Correct 1062 ms 4604 KB Output is correct
19 Correct 1173 ms 4704 KB Output is correct
20 Correct 1040 ms 4552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 304 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 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 304 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 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 272 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 1 ms 296 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 304 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 304 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 300 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 304 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 296 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 272 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 296 KB Output is correct
25 Correct 1 ms 296 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 304 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 304 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 300 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 4 ms 340 KB Output is correct
42 Correct 3 ms 340 KB Output is correct
43 Correct 4 ms 340 KB Output is correct
44 Correct 4 ms 340 KB Output is correct
45 Correct 5 ms 456 KB Output is correct
46 Correct 5 ms 468 KB Output is correct
47 Correct 7 ms 724 KB Output is correct
48 Correct 7 ms 596 KB Output is correct
49 Correct 9 ms 688 KB Output is correct
50 Correct 8 ms 684 KB Output is correct
51 Correct 10 ms 704 KB Output is correct
52 Correct 10 ms 708 KB Output is correct
53 Correct 7 ms 596 KB Output is correct
54 Correct 6 ms 552 KB Output is correct
55 Correct 7 ms 596 KB Output is correct
56 Correct 7 ms 596 KB Output is correct
57 Correct 8 ms 596 KB Output is correct
58 Correct 6 ms 556 KB Output is correct
59 Correct 6 ms 596 KB Output is correct
60 Correct 7 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1525 ms 4744 KB Output is correct
2 Correct 1507 ms 4752 KB Output is correct
3 Correct 1518 ms 4684 KB Output is correct
4 Correct 1518 ms 4624 KB Output is correct
5 Correct 1526 ms 4808 KB Output is correct
6 Correct 1513 ms 4592 KB Output is correct
7 Correct 1405 ms 4616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 82 ms 832 KB Output is correct
6 Correct 207 ms 1560 KB Output is correct
7 Correct 450 ms 2536 KB Output is correct
8 Correct 730 ms 3668 KB Output is correct
9 Correct 1058 ms 4624 KB Output is correct
10 Correct 606 ms 3384 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 269 ms 1888 KB Output is correct
13 Correct 356 ms 1768 KB Output is correct
14 Correct 267 ms 1840 KB Output is correct
15 Correct 682 ms 3516 KB Output is correct
16 Correct 775 ms 3444 KB Output is correct
17 Correct 663 ms 3564 KB Output is correct
18 Correct 1062 ms 4604 KB Output is correct
19 Correct 1173 ms 4704 KB Output is correct
20 Correct 1040 ms 4552 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 304 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 296 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 212 KB Output is correct
39 Correct 1 ms 272 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 296 KB Output is correct
45 Correct 1 ms 296 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 304 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 304 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 300 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 212 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 4 ms 340 KB Output is correct
62 Correct 3 ms 340 KB Output is correct
63 Correct 4 ms 340 KB Output is correct
64 Correct 4 ms 340 KB Output is correct
65 Correct 5 ms 456 KB Output is correct
66 Correct 5 ms 468 KB Output is correct
67 Correct 7 ms 724 KB Output is correct
68 Correct 7 ms 596 KB Output is correct
69 Correct 9 ms 688 KB Output is correct
70 Correct 8 ms 684 KB Output is correct
71 Correct 10 ms 704 KB Output is correct
72 Correct 10 ms 708 KB Output is correct
73 Correct 7 ms 596 KB Output is correct
74 Correct 6 ms 552 KB Output is correct
75 Correct 7 ms 596 KB Output is correct
76 Correct 7 ms 596 KB Output is correct
77 Correct 8 ms 596 KB Output is correct
78 Correct 6 ms 556 KB Output is correct
79 Correct 6 ms 596 KB Output is correct
80 Correct 7 ms 596 KB Output is correct
81 Correct 1525 ms 4744 KB Output is correct
82 Correct 1507 ms 4752 KB Output is correct
83 Correct 1518 ms 4684 KB Output is correct
84 Correct 1518 ms 4624 KB Output is correct
85 Correct 1526 ms 4808 KB Output is correct
86 Correct 1513 ms 4592 KB Output is correct
87 Correct 1405 ms 4616 KB Output is correct
88 Correct 222 ms 808 KB Output is correct
89 Correct 220 ms 912 KB Output is correct
90 Correct 487 ms 1500 KB Output is correct
91 Correct 492 ms 1568 KB Output is correct
92 Correct 908 ms 2716 KB Output is correct
93 Correct 872 ms 2492 KB Output is correct
94 Correct 1195 ms 3752 KB Output is correct
95 Correct 1184 ms 3624 KB Output is correct
96 Correct 1395 ms 4232 KB Output is correct
97 Correct 1388 ms 4288 KB Output is correct
98 Correct 1078 ms 3520 KB Output is correct
99 Correct 1097 ms 3456 KB Output is correct
100 Correct 1110 ms 3492 KB Output is correct
101 Correct 1102 ms 3560 KB Output is correct
102 Correct 1010 ms 3400 KB Output is correct
103 Correct 1043 ms 3304 KB Output is correct
104 Correct 1006 ms 3408 KB Output is correct
105 Correct 610 ms 3460 KB Output is correct