답안 #729326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729326 2023-04-23T19:35:45 Z tch1cherin Let's Win the Election (JOI22_ho_t3) C++17
66 / 100
2500 ms 992 KB
#include <bits/stdc++.h>
using namespace std;
 
const long double INF = 1e18;
 
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n), b(n);
  bool good = true;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    good &= b[i] == -1 || b[i] == a[i];
  }
  if (!good && n != k) {
    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int i, int j) {
      return b[i] < b[j];
    });
    vector<int> new_a(n), new_b(n);
    for (int i = 0; i < n; i++) {
      new_a[i] = a[order[i]];
      new_b[i] = b[order[i]];
    }
    a = new_a, b = new_b;
    long double ans = INF;
    for (int c = 0; c <= k; c++) {
      vector dp(k + 1, vector<long double>(c + 1, INF));
      dp[0][0] = 0;
      for (int i = 0; i < n; i++) {
        vector new_dp(n + 1, vector<long double>(c + 1, INF));
        for (int j = 0; j <= k; j++) {
          for (int l = 0; l <= c; l++) {
            if (j + 1 <= k && l + 1 <= c && b[i] != -1) {
              new_dp[j + 1][l + 1] = min(new_dp[j + 1][l + 1], dp[j][l] + (long double)b[i] / (l + 1));
            }
            if (j + 1 <= k) {
              new_dp[j + 1][l] = min(new_dp[j + 1][l], dp[j][l] + (long double)a[i] / (c + 1));
            }
            new_dp[j][l] = min(new_dp[j][l], dp[j][l]);
          }
        }
        dp = new_dp;
      }
      for (int i = k; i <= n; i++) {
        ans = min(ans, dp[i][c]);
      }
    }
    cout << ans << "\n";
  } else if (good) {
    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int i, int j) {
      return a[i] < a[j];
    });
    long double ans = 1e18;
    for (int max_c = 0; max_c <= n; max_c++) {
      int c = 1, cnt = 0;
      long double res = 0;
      for (int i : order) {
        if (a[i] == b[i] && c <= max_c) {
          res += (long double)a[i] / c;
          c++;
          cnt++;
        }
      }
      for (int i : order) {
        if (a[i] != b[i] && cnt < k) {
          res += (long double)a[i] / c;
          cnt++;
        }
      }
      if (cnt >= k) {
        ans = min(ans, res);
      }
    }
    cout << ans << "\n";
  } else {
    vector<int> order(n);
    iota(order.begin(), order.end(), 0);
    sort(order.begin(), order.end(), [&](int i, int j) {
      return b[i] < b[j];
    });
    vector<int> new_a(n), new_b(n);
    for (int i = 0; i < n; i++) {
      new_a[i] = a[order[i]];
      new_b[i] = b[order[i]];
    }
    a = new_a, b = new_b;
    long double ans = INF;
    for (int c = 0; c <= k; c++) {
      vector<long double> dp(c + 1, INF);
      dp[0] = 0;
      for (int i = 0; i < n; i++) {
        vector<long double> new_dp(c + 1, INF);
        for (int j = 0; j <= k; j++) {
          for (int l = 0; l <= c; l++) {
            if (j + 1 <= k && l + 1 <= c && b[i] != -1) {
              new_dp[l + 1] = min(new_dp[l + 1], dp[l] + (long double)b[i] / (l + 1));
            }
            if (j + 1 <= k) {
              new_dp[l] = min(new_dp[l], dp[l] + (long double)a[i] / (c + 1));
            }
          }
        }
        dp = new_dp;
      }
      ans = min(ans, dp[c]);
    }
    cout << ans << "\n";
  }
}
 
int main() {
  cout << fixed << setprecision(9);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}
# 결과 실행 시간 메모리 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 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
# 결과 실행 시간 메모리 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 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 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 212 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 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 212 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 356 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 340 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 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 212 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 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 356 KB Output is correct
25 Correct 2 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 15 ms 388 KB Output is correct
42 Correct 14 ms 340 KB Output is correct
43 Correct 54 ms 476 KB Output is correct
44 Correct 56 ms 552 KB Output is correct
45 Correct 158 ms 632 KB Output is correct
46 Correct 150 ms 656 KB Output is correct
47 Correct 353 ms 892 KB Output is correct
48 Correct 307 ms 828 KB Output is correct
49 Correct 564 ms 992 KB Output is correct
50 Correct 514 ms 944 KB Output is correct
51 Correct 636 ms 460 KB Output is correct
52 Correct 587 ms 376 KB Output is correct
53 Correct 309 ms 864 KB Output is correct
54 Correct 349 ms 776 KB Output is correct
55 Correct 313 ms 800 KB Output is correct
56 Correct 308 ms 776 KB Output is correct
57 Correct 320 ms 816 KB Output is correct
58 Correct 324 ms 948 KB Output is correct
59 Correct 323 ms 848 KB Output is correct
60 Correct 310 ms 800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2546 ms 456 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 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 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 3 ms 212 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct
21 Correct 0 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 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 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 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 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 2 ms 356 KB Output is correct
45 Correct 2 ms 212 KB Output is correct
46 Correct 2 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 2 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 2 ms 340 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 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 2 ms 340 KB Output is correct
61 Correct 15 ms 388 KB Output is correct
62 Correct 14 ms 340 KB Output is correct
63 Correct 54 ms 476 KB Output is correct
64 Correct 56 ms 552 KB Output is correct
65 Correct 158 ms 632 KB Output is correct
66 Correct 150 ms 656 KB Output is correct
67 Correct 353 ms 892 KB Output is correct
68 Correct 307 ms 828 KB Output is correct
69 Correct 564 ms 992 KB Output is correct
70 Correct 514 ms 944 KB Output is correct
71 Correct 636 ms 460 KB Output is correct
72 Correct 587 ms 376 KB Output is correct
73 Correct 309 ms 864 KB Output is correct
74 Correct 349 ms 776 KB Output is correct
75 Correct 313 ms 800 KB Output is correct
76 Correct 308 ms 776 KB Output is correct
77 Correct 320 ms 816 KB Output is correct
78 Correct 324 ms 948 KB Output is correct
79 Correct 323 ms 848 KB Output is correct
80 Correct 310 ms 800 KB Output is correct
81 Execution timed out 2546 ms 456 KB Time limit exceeded
82 Halted 0 ms 0 KB -