답안 #532207

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532207 2022-03-02T13:22:34 Z Jarif_Rahman Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
427 ms 4712 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
typedef double ld;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cerr.precision(100);
    cout.precision(100);

    int n, k; cin >> n >> k;
    vector<pair<int, int>> v(n);
    for(auto &p: v) cin >> p.f >> p.sc;

    sort(v.begin(), v.end(), [](pair<ld, ld> a, pair<ld, ld> b){
        swap(a.f, a.sc);
        swap(b.f, b.sc);
        if(a.f == -1) a.f = 1e9;
        if(b.f == -1) b.f = 1e9;
        return a < b;
    });

    vector<vector<ld>> last(n, vector<ld>(n+1, 1e6));
    for(int i = 0; i < n; i++) last[i][0] = 0;

    for(int c = 1; c <= n; c++){
        priority_queue<int> pq;
        int s = 0;
        for(int i = n-1; i >= n-c; i--) pq.push(v[i].f), s+=v[i].f;
        last[n-c][c] = s;
        for(int i = n-c-1; i >= 0; i--){
            if(v[i].f < pq.top()) s-=pq.top(), pq.pop(), pq.push(v[i].f), s+=v[i].f;
            last[i][c] = s;
        }
    }

    ld ans = last[0][k];

    for(int c = 0; c <= k; c++){
        vector<vector<ld>> dp(n, vector<ld>(c+1, 1e6));
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= min(i+1, c); j++){
                if(i == 0){
                    if(j == 0) dp[i][j] = ld(v[i].f)/ld(c+1);
                    else if(j == 1 && v[i].sc != -1) dp[i][j] = v[i].sc;
                    continue;
                }

                if(i >= j)
                    dp[i][j] = min(dp[i][j], dp[i-1][j]+ld(v[i].f)/ld(c+1));

                if(v[i].sc != -1 && j > 0)
                    dp[i][j] = min(dp[i][j], dp[i-1][j-1]+ld(v[i].sc)/ld(j));
            }
        }

        for(int i = 0; i < k; i++)
            ans = min(ans, dp[i][c] + (i == n-1 ? 0.0 : last[i+1][k-i-1]/ld(c+1)));
    }

    cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 10 ms 2524 KB Output is correct
6 Correct 26 ms 3068 KB Output is correct
7 Correct 81 ms 3488 KB Output is correct
8 Correct 174 ms 4012 KB Output is correct
9 Correct 281 ms 4612 KB Output is correct
10 Correct 150 ms 4052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 10 ms 2524 KB Output is correct
6 Correct 26 ms 3068 KB Output is correct
7 Correct 81 ms 3488 KB Output is correct
8 Correct 174 ms 4012 KB Output is correct
9 Correct 281 ms 4612 KB Output is correct
10 Correct 150 ms 4052 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 55 ms 3256 KB Output is correct
13 Correct 44 ms 3132 KB Output is correct
14 Correct 37 ms 3092 KB Output is correct
15 Correct 242 ms 3968 KB Output is correct
16 Correct 177 ms 3900 KB Output is correct
17 Correct 152 ms 3872 KB Output is correct
18 Correct 409 ms 4588 KB Output is correct
19 Correct 338 ms 4712 KB Output is correct
20 Correct 305 ms 4584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 204 KB Output is correct
38 Correct 1 ms 204 KB Output is correct
39 Correct 0 ms 204 KB Output is correct
40 Correct 1 ms 204 KB Output is correct
41 Correct 1 ms 400 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 2 ms 460 KB Output is correct
46 Correct 2 ms 460 KB Output is correct
47 Correct 2 ms 460 KB Output is correct
48 Correct 2 ms 460 KB Output is correct
49 Correct 3 ms 524 KB Output is correct
50 Correct 2 ms 460 KB Output is correct
51 Correct 3 ms 588 KB Output is correct
52 Correct 3 ms 580 KB Output is correct
53 Correct 2 ms 460 KB Output is correct
54 Correct 2 ms 460 KB Output is correct
55 Correct 2 ms 460 KB Output is correct
56 Correct 2 ms 460 KB Output is correct
57 Correct 3 ms 460 KB Output is correct
58 Correct 2 ms 460 KB Output is correct
59 Correct 2 ms 460 KB Output is correct
60 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 427 ms 4588 KB Output is correct
2 Correct 406 ms 4556 KB Output is correct
3 Correct 420 ms 4636 KB Output is correct
4 Correct 404 ms 4512 KB Output is correct
5 Correct 418 ms 4572 KB Output is correct
6 Correct 402 ms 4540 KB Output is correct
7 Correct 418 ms 4536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 10 ms 2524 KB Output is correct
6 Correct 26 ms 3068 KB Output is correct
7 Correct 81 ms 3488 KB Output is correct
8 Correct 174 ms 4012 KB Output is correct
9 Correct 281 ms 4612 KB Output is correct
10 Correct 150 ms 4052 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 55 ms 3256 KB Output is correct
13 Correct 44 ms 3132 KB Output is correct
14 Correct 37 ms 3092 KB Output is correct
15 Correct 242 ms 3968 KB Output is correct
16 Correct 177 ms 3900 KB Output is correct
17 Correct 152 ms 3872 KB Output is correct
18 Correct 409 ms 4588 KB Output is correct
19 Correct 338 ms 4712 KB Output is correct
20 Correct 305 ms 4584 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 0 ms 204 KB Output is correct
36 Correct 0 ms 204 KB Output is correct
37 Correct 0 ms 204 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 1 ms 204 KB Output is correct
40 Correct 0 ms 204 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 1 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 0 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 0 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 1 ms 204 KB Output is correct
55 Correct 0 ms 204 KB Output is correct
56 Correct 1 ms 204 KB Output is correct
57 Correct 1 ms 204 KB Output is correct
58 Correct 1 ms 204 KB Output is correct
59 Correct 0 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 400 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 2 ms 460 KB Output is correct
66 Correct 2 ms 460 KB Output is correct
67 Correct 2 ms 460 KB Output is correct
68 Correct 2 ms 460 KB Output is correct
69 Correct 3 ms 524 KB Output is correct
70 Correct 2 ms 460 KB Output is correct
71 Correct 3 ms 588 KB Output is correct
72 Correct 3 ms 580 KB Output is correct
73 Correct 2 ms 460 KB Output is correct
74 Correct 2 ms 460 KB Output is correct
75 Correct 2 ms 460 KB Output is correct
76 Correct 2 ms 460 KB Output is correct
77 Correct 3 ms 460 KB Output is correct
78 Correct 2 ms 460 KB Output is correct
79 Correct 2 ms 460 KB Output is correct
80 Correct 2 ms 460 KB Output is correct
81 Correct 427 ms 4588 KB Output is correct
82 Correct 406 ms 4556 KB Output is correct
83 Correct 420 ms 4636 KB Output is correct
84 Correct 404 ms 4512 KB Output is correct
85 Correct 418 ms 4572 KB Output is correct
86 Correct 402 ms 4540 KB Output is correct
87 Correct 418 ms 4536 KB Output is correct
88 Correct 14 ms 2524 KB Output is correct
89 Correct 13 ms 2524 KB Output is correct
90 Correct 39 ms 3004 KB Output is correct
91 Correct 38 ms 3000 KB Output is correct
92 Correct 122 ms 3508 KB Output is correct
93 Correct 128 ms 3656 KB Output is correct
94 Correct 251 ms 4012 KB Output is correct
95 Correct 248 ms 4092 KB Output is correct
96 Correct 345 ms 4384 KB Output is correct
97 Correct 360 ms 4368 KB Output is correct
98 Correct 221 ms 3880 KB Output is correct
99 Correct 217 ms 3988 KB Output is correct
100 Correct 222 ms 3880 KB Output is correct
101 Correct 221 ms 3952 KB Output is correct
102 Correct 218 ms 3972 KB Output is correct
103 Correct 220 ms 3872 KB Output is correct
104 Correct 222 ms 3888 KB Output is correct
105 Correct 213 ms 3952 KB Output is correct