Submission #554436

# Submission time Handle Problem Language Result Execution time Memory
554436 2022-04-28T11:41:02 Z Ronin13 Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
435 ms 2384 KB
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
using namespace std;

const double inf = 1e9 + 1;

int main(){
    int n; cin >> n;
    int k; cin >> k;
    pair<double, double> a[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> a[i].s >> a[i].f;
        if(a[i].f == -1) a[i].f = inf;
    }
    sort(a + 1, a + 1 + n);
    for(int i = 1; i <= n; i++){
        //cout << a[i].f << ' ' << a[i].s << "\n";
    }
    double ans = inf;
    for(double x = 0; x <= n; x++){
        double dp[n + 1][n + 1];
        for(int i = 0; i <= n; i++){
            for(int j = 0; j <= n; j++) dp[i][j] = inf;
        }
        dp[0][0] = 0;
        for(int i = 1; i <= n; i++){
            for(int j = 0; j <= n; j++){
                double i1 = i;
                double j1 = j;
                if(j > 0)dp[i][j] =min(dp[i][j], dp[i - 1][j - 1] + a[i].f / j1);
                dp[(int)i][(int)j] = min(dp[i][j], dp[i - 1][j] + a[i].s / (x + 1));
            }
        }
        double cursum = 0;
        multiset <pair<double, int> > st;
        for(int i = 1; i <= n; i++){
            cursum += a[i].s;
            st.insert({a[i].s, i});
        }
        while(st.size() > k) {
            cursum -= st.rbegin() -> f;
            st.erase(st.find(*st.rbegin()));
        }
        for(int i = 1; i <= n; i++){
            double cur = dp[i - 1][(int)x];
            cur += cursum / (x + 1);
            if(ans > cur){
                //cout << dp[i - 1][x] << "\n";
                //cout << x << ' ' << i;
                //cout << "\n";
                ans = cur;
            }
            multiset <pair<double, int> > :: iterator it = st.find({a[i].s, i});
            if(it != st.end()){
                cursum -= a[i].s;
                st.erase({a[i].s, i});
            }
            if(st.size() > k - i && !st.empty()){
                cursum -= st.rbegin() -> f;
                st.erase(st.find(*st.rbegin()));
            }
        }
        ans = min(ans, dp[n][(int)x]);
    }
    cout << fixed << setprecision(7) << ans;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:35:24: warning: unused variable 'i1' [-Wunused-variable]
   35 |                 double i1 = i;
      |                        ^~
Main.cpp:47:25: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<double, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |         while(st.size() > k) {
      |               ~~~~~~~~~~^~~
Main.cpp:65:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<double, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |             if(st.size() > k - i && !st.empty()){
      |                ~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 380 ms 2276 KB Output is correct
6 Correct 420 ms 2280 KB Output is correct
7 Correct 414 ms 2276 KB Output is correct
8 Correct 372 ms 2260 KB Output is correct
9 Correct 402 ms 2276 KB Output is correct
10 Correct 384 ms 2276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 380 ms 2276 KB Output is correct
6 Correct 420 ms 2280 KB Output is correct
7 Correct 414 ms 2276 KB Output is correct
8 Correct 372 ms 2260 KB Output is correct
9 Correct 402 ms 2276 KB Output is correct
10 Correct 384 ms 2276 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 362 ms 2280 KB Output is correct
13 Correct 347 ms 2284 KB Output is correct
14 Correct 349 ms 2288 KB Output is correct
15 Correct 352 ms 2260 KB Output is correct
16 Correct 422 ms 2260 KB Output is correct
17 Correct 365 ms 2280 KB Output is correct
18 Correct 379 ms 2276 KB Output is correct
19 Correct 367 ms 2260 KB Output is correct
20 Correct 359 ms 2276 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 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 1 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 1 ms 304 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 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 1 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 1 ms 304 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 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 1 ms 212 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 296 KB Output is correct
40 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 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 1 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 1 ms 304 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 300 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 300 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 1 ms 212 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 296 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 5 ms 304 KB Output is correct
42 Correct 5 ms 340 KB Output is correct
43 Correct 5 ms 288 KB Output is correct
44 Correct 4 ms 340 KB Output is correct
45 Correct 5 ms 340 KB Output is correct
46 Correct 5 ms 340 KB Output is correct
47 Correct 4 ms 340 KB Output is correct
48 Correct 5 ms 340 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 7 ms 384 KB Output is correct
52 Correct 5 ms 340 KB Output is correct
53 Correct 5 ms 340 KB Output is correct
54 Correct 4 ms 340 KB Output is correct
55 Correct 5 ms 340 KB Output is correct
56 Correct 4 ms 296 KB Output is correct
57 Correct 5 ms 380 KB Output is correct
58 Correct 6 ms 388 KB Output is correct
59 Correct 4 ms 340 KB Output is correct
60 Correct 5 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 383 ms 2292 KB Output is correct
2 Correct 377 ms 2260 KB Output is correct
3 Correct 395 ms 2280 KB Output is correct
4 Correct 406 ms 2280 KB Output is correct
5 Correct 375 ms 2288 KB Output is correct
6 Correct 435 ms 2280 KB Output is correct
7 Correct 383 ms 2276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 380 ms 2276 KB Output is correct
6 Correct 420 ms 2280 KB Output is correct
7 Correct 414 ms 2276 KB Output is correct
8 Correct 372 ms 2260 KB Output is correct
9 Correct 402 ms 2276 KB Output is correct
10 Correct 384 ms 2276 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 362 ms 2280 KB Output is correct
13 Correct 347 ms 2284 KB Output is correct
14 Correct 349 ms 2288 KB Output is correct
15 Correct 352 ms 2260 KB Output is correct
16 Correct 422 ms 2260 KB Output is correct
17 Correct 365 ms 2280 KB Output is correct
18 Correct 379 ms 2276 KB Output is correct
19 Correct 367 ms 2260 KB Output is correct
20 Correct 359 ms 2276 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 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 1 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 1 ms 304 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 300 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 212 KB Output is correct
46 Correct 1 ms 296 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 304 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 300 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 1 ms 212 KB Output is correct
59 Correct 1 ms 296 KB Output is correct
60 Correct 1 ms 212 KB Output is correct
61 Correct 5 ms 304 KB Output is correct
62 Correct 5 ms 340 KB Output is correct
63 Correct 5 ms 288 KB Output is correct
64 Correct 4 ms 340 KB Output is correct
65 Correct 5 ms 340 KB Output is correct
66 Correct 5 ms 340 KB Output is correct
67 Correct 4 ms 340 KB Output is correct
68 Correct 5 ms 340 KB Output is correct
69 Correct 5 ms 384 KB Output is correct
70 Correct 5 ms 384 KB Output is correct
71 Correct 7 ms 384 KB Output is correct
72 Correct 5 ms 340 KB Output is correct
73 Correct 5 ms 340 KB Output is correct
74 Correct 4 ms 340 KB Output is correct
75 Correct 5 ms 340 KB Output is correct
76 Correct 4 ms 296 KB Output is correct
77 Correct 5 ms 380 KB Output is correct
78 Correct 6 ms 388 KB Output is correct
79 Correct 4 ms 340 KB Output is correct
80 Correct 5 ms 300 KB Output is correct
81 Correct 383 ms 2292 KB Output is correct
82 Correct 377 ms 2260 KB Output is correct
83 Correct 395 ms 2280 KB Output is correct
84 Correct 406 ms 2280 KB Output is correct
85 Correct 375 ms 2288 KB Output is correct
86 Correct 435 ms 2280 KB Output is correct
87 Correct 383 ms 2276 KB Output is correct
88 Correct 383 ms 2288 KB Output is correct
89 Correct 366 ms 2380 KB Output is correct
90 Correct 361 ms 2276 KB Output is correct
91 Correct 365 ms 2384 KB Output is correct
92 Correct 352 ms 2280 KB Output is correct
93 Correct 367 ms 2380 KB Output is correct
94 Correct 367 ms 2284 KB Output is correct
95 Correct 374 ms 2380 KB Output is correct
96 Correct 380 ms 2276 KB Output is correct
97 Correct 380 ms 2280 KB Output is correct
98 Correct 361 ms 2260 KB Output is correct
99 Correct 419 ms 2280 KB Output is correct
100 Correct 392 ms 2292 KB Output is correct
101 Correct 368 ms 2296 KB Output is correct
102 Correct 397 ms 2276 KB Output is correct
103 Correct 425 ms 2280 KB Output is correct
104 Correct 368 ms 2276 KB Output is correct
105 Correct 373 ms 2280 KB Output is correct