Submission #729309

# Submission time Handle Problem Language Result Execution time Memory
729309 2023-04-23T19:03:36 Z tch1cherin Let's Win the Election (JOI22_ho_t3) C++17
56 / 100
2500 ms 1992 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;
  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";
}

int main() {
  cout << fixed << setprecision(9);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1465 ms 1420 KB Output is correct
6 Execution timed out 2552 ms 1992 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1465 ms 1420 KB Output is correct
6 Execution timed out 2552 ms 1992 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 0 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 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory 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 0 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 0 ms 212 KB Output is correct
14 Correct 0 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 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 1 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 1 ms 340 KB Output is correct
25 Correct 3 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 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 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 1 ms 340 KB Output is correct
# Verdict Execution time Memory 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 0 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 0 ms 212 KB Output is correct
14 Correct 0 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 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 1 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 1 ms 340 KB Output is correct
25 Correct 3 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 1 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 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 1 ms 340 KB Output is correct
41 Correct 13 ms 348 KB Output is correct
42 Correct 13 ms 316 KB Output is correct
43 Correct 47 ms 460 KB Output is correct
44 Correct 61 ms 524 KB Output is correct
45 Correct 175 ms 632 KB Output is correct
46 Correct 146 ms 624 KB Output is correct
47 Correct 313 ms 900 KB Output is correct
48 Correct 294 ms 796 KB Output is correct
49 Correct 551 ms 936 KB Output is correct
50 Correct 510 ms 956 KB Output is correct
51 Correct 1002 ms 1188 KB Output is correct
52 Correct 1000 ms 916 KB Output is correct
53 Correct 304 ms 840 KB Output is correct
54 Correct 309 ms 812 KB Output is correct
55 Correct 330 ms 952 KB Output is correct
56 Correct 295 ms 832 KB Output is correct
57 Correct 310 ms 928 KB Output is correct
58 Correct 305 ms 832 KB Output is correct
59 Correct 330 ms 816 KB Output is correct
60 Correct 326 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2570 ms 836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 268 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1465 ms 1420 KB Output is correct
6 Execution timed out 2552 ms 1992 KB Time limit exceeded
7 Halted 0 ms 0 KB -