답안 #730367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730367 2023-04-25T18:09:13 Z tch1cherin Let's Win the Election (JOI22_ho_t3) C++17
56 / 100
2500 ms 5796 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);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> 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];
  });
  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;
  auto Solve = [&n, &k, &a, &b](int c) {
    long double ans = INF;
    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]);
    }
    return ans;
  };
  int l = 0, r = k;
  while (r - l > 2) {
    int m1 = l + (r - l) / 3;
    int m2 = r - (r - l) / 3;
    if (Solve(m1) < Solve(m2)) {
      r = m2;
    } else {
      l = m1;
    }
  }
  cout << min({Solve(l), Solve(l + 1), Solve(l + 2)}) << "\n";
}
 
int main() {
  cout << fixed << setprecision(9);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 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 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 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 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 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 2 ms 316 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 312 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 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 2 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 2 ms 320 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 320 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 2 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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 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 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 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 2 ms 316 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 2 ms 340 KB Output is correct
23 Correct 1 ms 324 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 4 ms 340 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 312 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 3 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 2 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 2 ms 320 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 2 ms 320 KB Output is correct
38 Correct 2 ms 340 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 12 ms 340 KB Output is correct
42 Correct 14 ms 376 KB Output is correct
43 Correct 21 ms 340 KB Output is correct
44 Correct 34 ms 340 KB Output is correct
45 Correct 92 ms 500 KB Output is correct
46 Correct 59 ms 468 KB Output is correct
47 Correct 93 ms 480 KB Output is correct
48 Correct 135 ms 560 KB Output is correct
49 Correct 230 ms 756 KB Output is correct
50 Correct 133 ms 672 KB Output is correct
51 Correct 255 ms 548 KB Output is correct
52 Correct 369 ms 592 KB Output is correct
53 Correct 57 ms 468 KB Output is correct
54 Correct 93 ms 600 KB Output is correct
55 Correct 143 ms 556 KB Output is correct
56 Correct 70 ms 468 KB Output is correct
57 Correct 135 ms 596 KB Output is correct
58 Correct 155 ms 584 KB Output is correct
59 Correct 145 ms 576 KB Output is correct
60 Correct 132 ms 552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2550 ms 5796 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -