답안 #729303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729303 2023-04-23T18:35:53 Z tch1cherin Let's Win the Election (JOI22_ho_t3) C++17
33 / 100
2500 ms 312 KB
#include <bits/stdc++.h>
using namespace std;

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) {
    vector<int> order_a(n), order_b(n);
    iota(order_a.begin(), order_a.end(), 0);
    iota(order_b.begin(), order_b.end(), 0);
    sort(order_a.begin(), order_a.end(), [&](int i, int j) {
      return a[i] < a[j];
    });
    sort(order_b.begin(), order_b.end(), [&](int i, int j) {
      return b[i] < b[j];
    });
    long double ans = 1e18;
    for (int mask = 0; mask < (1 << n); mask++) {
      int c = 1, cnt = 0;
      long double res = 0;
      vector<bool> used(n, false);
      for (int i : order_b) {
        if (((mask >> i) & 1) && b[i] != -1) {
          res += (long double)b[i] / c;
          c++;
          cnt++;
          used[i] = true;
        }
      }
      for (int i : order_a) {
        if (cnt < k && !used[i]) {
          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 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";
  }
}

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 0 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 2 ms 212 KB Output is correct
8 Correct 2 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 0 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 2 ms 212 KB Output is correct
8 Correct 2 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 252 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 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 2 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 120 ms 212 KB Output is correct
17 Correct 148 ms 296 KB Output is correct
18 Correct 125 ms 292 KB Output is correct
19 Correct 141 ms 308 KB Output is correct
20 Correct 121 ms 296 KB Output is correct
21 Correct 134 ms 312 KB Output is correct
22 Correct 164 ms 300 KB Output is correct
23 Correct 129 ms 300 KB Output is correct
24 Correct 114 ms 300 KB Output is correct
25 Correct 171 ms 212 KB Output is correct
26 Correct 171 ms 296 KB Output is correct
27 Correct 135 ms 296 KB Output is correct
28 Correct 141 ms 304 KB Output is correct
29 Correct 143 ms 212 KB Output is correct
30 Correct 139 ms 300 KB Output is correct
31 Correct 150 ms 296 KB Output is correct
32 Correct 161 ms 300 KB Output is correct
33 Correct 130 ms 212 KB Output is correct
34 Correct 147 ms 300 KB Output is correct
35 Correct 149 ms 296 KB Output is correct
36 Correct 151 ms 212 KB Output is correct
37 Correct 147 ms 212 KB Output is correct
38 Correct 135 ms 300 KB Output is correct
39 Correct 142 ms 304 KB Output is correct
40 Correct 148 ms 296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 120 ms 212 KB Output is correct
17 Correct 148 ms 296 KB Output is correct
18 Correct 125 ms 292 KB Output is correct
19 Correct 141 ms 308 KB Output is correct
20 Correct 121 ms 296 KB Output is correct
21 Correct 134 ms 312 KB Output is correct
22 Correct 164 ms 300 KB Output is correct
23 Correct 129 ms 300 KB Output is correct
24 Correct 114 ms 300 KB Output is correct
25 Correct 171 ms 212 KB Output is correct
26 Correct 171 ms 296 KB Output is correct
27 Correct 135 ms 296 KB Output is correct
28 Correct 141 ms 304 KB Output is correct
29 Correct 143 ms 212 KB Output is correct
30 Correct 139 ms 300 KB Output is correct
31 Correct 150 ms 296 KB Output is correct
32 Correct 161 ms 300 KB Output is correct
33 Correct 130 ms 212 KB Output is correct
34 Correct 147 ms 300 KB Output is correct
35 Correct 149 ms 296 KB Output is correct
36 Correct 151 ms 212 KB Output is correct
37 Correct 147 ms 212 KB Output is correct
38 Correct 135 ms 300 KB Output is correct
39 Correct 142 ms 304 KB Output is correct
40 Correct 148 ms 296 KB Output is correct
41 Incorrect 1 ms 212 KB Output isn't correct
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2564 ms 212 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 0 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 2 ms 212 KB Output is correct
8 Correct 2 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 252 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 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 2 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 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 1 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 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 120 ms 212 KB Output is correct
37 Correct 148 ms 296 KB Output is correct
38 Correct 125 ms 292 KB Output is correct
39 Correct 141 ms 308 KB Output is correct
40 Correct 121 ms 296 KB Output is correct
41 Correct 134 ms 312 KB Output is correct
42 Correct 164 ms 300 KB Output is correct
43 Correct 129 ms 300 KB Output is correct
44 Correct 114 ms 300 KB Output is correct
45 Correct 171 ms 212 KB Output is correct
46 Correct 171 ms 296 KB Output is correct
47 Correct 135 ms 296 KB Output is correct
48 Correct 141 ms 304 KB Output is correct
49 Correct 143 ms 212 KB Output is correct
50 Correct 139 ms 300 KB Output is correct
51 Correct 150 ms 296 KB Output is correct
52 Correct 161 ms 300 KB Output is correct
53 Correct 130 ms 212 KB Output is correct
54 Correct 147 ms 300 KB Output is correct
55 Correct 149 ms 296 KB Output is correct
56 Correct 151 ms 212 KB Output is correct
57 Correct 147 ms 212 KB Output is correct
58 Correct 135 ms 300 KB Output is correct
59 Correct 142 ms 304 KB Output is correct
60 Correct 148 ms 296 KB Output is correct
61 Incorrect 1 ms 212 KB Output isn't correct
62 Halted 0 ms 0 KB -