Submission #794829

# Submission time Handle Problem Language Result Execution time Memory
794829 2023-07-27T00:42:00 Z gun_gan Let's Win the Election (JOI22_ho_t3) C++17
56 / 100
35 ms 9392 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int MX = 105;
const double eps = 1e-9;
 
int N, K;
int a[MX], b[MX];
double dp[MX][MX][MX];
 
vector<pair<int, int>> v;

double f(int x) {
      for(int i = 0; i < MX; i++)
                  for(int j = 0; j < MX; j++)
                        for(int k = 0; k < MX; k++)
                              dp[i][j][k] = 1e9;
       
      dp[0][0][0] = 0;
      for(int i = 0; i < N; i++) {
            for(int j = 0; j <= N; j++) { // votes
                  for(int k = 0; k <= N; k++) { // num of collaborator
                        if(dp[i][j][k] == 1e9) continue;
 
                        // skip
                        dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);

                        // ambil vote
                        dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + (double) v[i].second / (x + 1));
                        
                        // ambil collaborator
                        if(v[i].first != 1e9) 
                              dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k] + (double) v[i].first / (k + 1));
                  }
            }
      }

      return dp[N][K][x];
}
 
int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);

      cin >> N >> K;
 
      int tot = 0;
      for(int i = 1; i <= N; i++) {
            cin >> a[i] >> b[i];
            if(b[i] != -1) tot++;
            else b[i] = 1e9;
            v.push_back({b[i], a[i]});
      }
 
      sort(v.begin(), v.end());

      double ans = 1e9;
      int l = 0, r = min(K, tot);

      while(r - l > 1) {
            int mid = (l + r) >> 1;
            if(f(mid) > f(mid + 1)) 
                  l = mid;
            else 
                  r = mid;
      } 

      cout << fixed << setprecision(15) << min(f(l), f(l + 1)) << '\n';
 
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:57:14: warning: unused variable 'ans' [-Wunused-variable]
   57 |       double ans = 1e9;
      |              ^~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 5 ms 9300 KB Output is correct
3 Correct 5 ms 9288 KB Output is correct
4 Correct 5 ms 9300 KB Output is correct
5 Runtime error 1 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 5 ms 9300 KB Output is correct
3 Correct 5 ms 9288 KB Output is correct
4 Correct 5 ms 9300 KB Output is correct
5 Runtime error 1 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9288 KB Output is correct
2 Correct 5 ms 9300 KB Output is correct
3 Correct 6 ms 9300 KB Output is correct
4 Correct 7 ms 9348 KB Output is correct
5 Correct 7 ms 9284 KB Output is correct
6 Correct 7 ms 9300 KB Output is correct
7 Correct 8 ms 9300 KB Output is correct
8 Correct 6 ms 9300 KB Output is correct
9 Correct 7 ms 9292 KB Output is correct
10 Correct 8 ms 9300 KB Output is correct
11 Correct 9 ms 9300 KB Output is correct
12 Correct 7 ms 9288 KB Output is correct
13 Correct 6 ms 9288 KB Output is correct
14 Correct 7 ms 9300 KB Output is correct
15 Correct 7 ms 9284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9288 KB Output is correct
2 Correct 5 ms 9300 KB Output is correct
3 Correct 6 ms 9300 KB Output is correct
4 Correct 7 ms 9348 KB Output is correct
5 Correct 7 ms 9284 KB Output is correct
6 Correct 7 ms 9300 KB Output is correct
7 Correct 8 ms 9300 KB Output is correct
8 Correct 6 ms 9300 KB Output is correct
9 Correct 7 ms 9292 KB Output is correct
10 Correct 8 ms 9300 KB Output is correct
11 Correct 9 ms 9300 KB Output is correct
12 Correct 7 ms 9288 KB Output is correct
13 Correct 6 ms 9288 KB Output is correct
14 Correct 7 ms 9300 KB Output is correct
15 Correct 7 ms 9284 KB Output is correct
16 Correct 6 ms 9300 KB Output is correct
17 Correct 11 ms 9300 KB Output is correct
18 Correct 8 ms 9300 KB Output is correct
19 Correct 9 ms 9384 KB Output is correct
20 Correct 12 ms 9300 KB Output is correct
21 Correct 9 ms 9300 KB Output is correct
22 Correct 10 ms 9384 KB Output is correct
23 Correct 9 ms 9360 KB Output is correct
24 Correct 8 ms 9384 KB Output is correct
25 Correct 13 ms 9300 KB Output is correct
26 Correct 9 ms 9300 KB Output is correct
27 Correct 8 ms 9300 KB Output is correct
28 Correct 9 ms 9300 KB Output is correct
29 Correct 11 ms 9380 KB Output is correct
30 Correct 9 ms 9300 KB Output is correct
31 Correct 9 ms 9288 KB Output is correct
32 Correct 8 ms 9300 KB Output is correct
33 Correct 8 ms 9300 KB Output is correct
34 Correct 7 ms 9300 KB Output is correct
35 Correct 12 ms 9300 KB Output is correct
36 Correct 9 ms 9388 KB Output is correct
37 Correct 9 ms 9380 KB Output is correct
38 Correct 9 ms 9388 KB Output is correct
39 Correct 9 ms 9272 KB Output is correct
40 Correct 9 ms 9384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9288 KB Output is correct
2 Correct 5 ms 9300 KB Output is correct
3 Correct 6 ms 9300 KB Output is correct
4 Correct 7 ms 9348 KB Output is correct
5 Correct 7 ms 9284 KB Output is correct
6 Correct 7 ms 9300 KB Output is correct
7 Correct 8 ms 9300 KB Output is correct
8 Correct 6 ms 9300 KB Output is correct
9 Correct 7 ms 9292 KB Output is correct
10 Correct 8 ms 9300 KB Output is correct
11 Correct 9 ms 9300 KB Output is correct
12 Correct 7 ms 9288 KB Output is correct
13 Correct 6 ms 9288 KB Output is correct
14 Correct 7 ms 9300 KB Output is correct
15 Correct 7 ms 9284 KB Output is correct
16 Correct 6 ms 9300 KB Output is correct
17 Correct 11 ms 9300 KB Output is correct
18 Correct 8 ms 9300 KB Output is correct
19 Correct 9 ms 9384 KB Output is correct
20 Correct 12 ms 9300 KB Output is correct
21 Correct 9 ms 9300 KB Output is correct
22 Correct 10 ms 9384 KB Output is correct
23 Correct 9 ms 9360 KB Output is correct
24 Correct 8 ms 9384 KB Output is correct
25 Correct 13 ms 9300 KB Output is correct
26 Correct 9 ms 9300 KB Output is correct
27 Correct 8 ms 9300 KB Output is correct
28 Correct 9 ms 9300 KB Output is correct
29 Correct 11 ms 9380 KB Output is correct
30 Correct 9 ms 9300 KB Output is correct
31 Correct 9 ms 9288 KB Output is correct
32 Correct 8 ms 9300 KB Output is correct
33 Correct 8 ms 9300 KB Output is correct
34 Correct 7 ms 9300 KB Output is correct
35 Correct 12 ms 9300 KB Output is correct
36 Correct 9 ms 9388 KB Output is correct
37 Correct 9 ms 9380 KB Output is correct
38 Correct 9 ms 9388 KB Output is correct
39 Correct 9 ms 9272 KB Output is correct
40 Correct 9 ms 9384 KB Output is correct
41 Correct 21 ms 9300 KB Output is correct
42 Correct 21 ms 9260 KB Output is correct
43 Correct 29 ms 9368 KB Output is correct
44 Correct 24 ms 9392 KB Output is correct
45 Correct 31 ms 9380 KB Output is correct
46 Correct 26 ms 9392 KB Output is correct
47 Correct 30 ms 9300 KB Output is correct
48 Correct 26 ms 9284 KB Output is correct
49 Correct 35 ms 9364 KB Output is correct
50 Correct 26 ms 9384 KB Output is correct
51 Correct 32 ms 9300 KB Output is correct
52 Correct 29 ms 9292 KB Output is correct
53 Correct 28 ms 9300 KB Output is correct
54 Correct 28 ms 9300 KB Output is correct
55 Correct 28 ms 9300 KB Output is correct
56 Correct 29 ms 9280 KB Output is correct
57 Correct 31 ms 9380 KB Output is correct
58 Correct 28 ms 9364 KB Output is correct
59 Correct 28 ms 9300 KB Output is correct
60 Correct 28 ms 9300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9300 KB Output is correct
2 Correct 5 ms 9300 KB Output is correct
3 Correct 5 ms 9288 KB Output is correct
4 Correct 5 ms 9300 KB Output is correct
5 Runtime error 1 ms 468 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -