답안 #750872

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
750872 2023-05-30T12:06:54 Z Kihihihi Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
356 ms 4952 KB
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <ctime>
#include <chrono>
#include <cstdio>
#include <random>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <queue>
#include <bitset>
#include <list>
#include <fstream>
#include <functional>
#include <complex>
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

short skip_cin = 0;
const long long INF = 1e9, MOD = 1e9 + 7, MOD2 = 998244353, LOG = 19;
const long double EPS = 1e-9, PI = acos(-1);

void solve()
{
    long long n, k;
    vector<pair<double, double>> v;
    cin >> n >> k;
    v.resize(n);
    for (long long i = 0; i < n; i++)
    {
        cin >> v[i].first >> v[i].second;
        if (v[i].second == -1)
        {
            v[i].second = INF;
        }
    }
    sort(v.begin(), v.end(),
        [](pair<double, double>& x, pair<double, double>& y)
        {
            if (x.second == y.second)
            {
                return x.first > y.first;
            }
            return x.second < y.second;
        }
    );

    vector<vector<double>> srta(n + 1);
    for (long long i = n - 1; i > -1; i--)
    {
        srta[i] = srta[i + 1];
        srta[i].push_back(v[i].first);
        sort(srta[i].begin(), srta[i].end());
    }

    double ans = INF;
    for (long long fr = 0; fr < k + 1; fr++)
    {
        vector<vector<double>> dp(n + 1, vector<double>(fr + 1, INF));
        dp[0][0] = 0;
        for (long long i = 0; i < n; i++)
        {
            for (long long j = 0; j < fr + 1; j++)
            {
                if (j > 0)
                {
                    dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - 1] + v[i].second / (double)(j));
                }
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + v[i].first / (double)(fr + 1));
            }
        }

        for (long long i = fr; i < n + 1; i++)
        {
            if (srta[i].size() < k - i)
            {
                break;
            }

            double add = 0;
            for (long long j = 0; j < k - i; j++)
            {
                add += srta[i][j];
            }
            add /= (fr + 1);
            ans = min(ans, dp[i][fr] + add);
        }
    }
    cout << fixed << setprecision(20) << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    srand(time(NULL));

    int tst = 1;
    //cin >> tst;
    while (tst--)
    {
        solve();
    }

    return 0;
}

/*
<3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠤⠖⠚⢉⣩⣭⡭⠛⠓⠲⠦⣄⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢀⡴⠋⠁⠀⠀⠊⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠳⢦⡀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⡴⠃⢀⡴⢳⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣆⠀⠀⠀
⠀⠀⠀⠀⡾⠁⣠⠋⠀⠈⢧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢧⠀⠀
⠀⠀⠀⣸⠁⢰⠃⠀⠀⠀⠈⢣⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣇⠀
⠀⠀⠀⡇⠀⡾⡀⠀⠀⠀⠀⣀⣹⣆⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⠀
⠀⠀⢸⠃⢀⣇⡈⠀⠀⠀⠀⠀⠀⢀⡑⢄⡀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇
⠀⠀⢸⠀⢻⡟⡻⢶⡆⠀⠀⠀⠀⡼⠟⡳⢿⣦⡑⢄⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇
⠀⠀⣸⠀⢸⠃⡇⢀⠇⠀⠀⠀⠀⠀⡼⠀⠀⠈⣿⡗⠂⠀⠀⠀⠀⠀⠀⠀⢸⠁
⠀⠀⡏⠀⣼⠀⢳⠊⠀⠀⠀⠀⠀⠀⠱⣀⣀⠔⣸⠁⠀⠀⠀⠀⠀⠀⠀⢠⡟⠀
⠀⠀⡇⢀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⢸⠃⠀
⠀⢸⠃⠘⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⠁⠀⠀⢀⠀⠀⠀⠀⠀⣾⠀⠀
⠀⣸⠀⠀⠹⡄⠀⠀⠈⠁⠀⠀⠀⠀⠀⠀⠀⡞⠀⠀⠀⠸⠀⠀⠀⠀⠀⡇⠀⠀
⠀⡏⠀⠀⠀⠙⣆⠀⠀⠀⠀⠀⠀⠀⢀⣠⢶⡇⠀⠀⢰⡀⠀⠀⠀⠀⠀⡇⠀⠀
⢰⠇⡄⠀⠀⠀⡿⢣⣀⣀⣀⡤⠴⡞⠉⠀⢸⠀⠀⠀⣿⡇⠀⠀⠀⠀⠀⣧⠀⠀
⣸⠀⡇⠀⠀⠀⠀⠀⠀⠉⠀⠀⠀⢹⠀⠀⢸⠀⠀⢀⣿⠇⠀⠀⠀⠁⠀⢸⠀⠀
⣿⠀⡇⠀⠀⠀⠀⠀⢀⡤⠤⠶⠶⠾⠤⠄⢸⠀⡀⠸⣿⣀⠀⠀⠀⠀⠀⠈⣇⠀
⡇⠀⡇⠀⠀⡀⠀⡴⠋⠀⠀⠀⠀⠀⠀⠀⠸⡌⣵⡀⢳⡇⠀⠀⠀⠀⠀⠀⢹⡀
⡇⠀⠇⠀⠀⡇⡸⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠮⢧⣀⣻⢂⠀⠀⠀⠀⠀⠀⢧
⣇⠀⢠⠀⠀⢳⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡎⣆⠀⠀⠀⠀⠀⠘
⢻⠀⠈⠰⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠰⠘⢮⣧⡀⠀⠀⠀⠀
⠸⡆⠀⠀⠇⣾⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠆⠀⠀⠀⠀⠀⠀⠀⠙⠳⣄⡀⢢⡀
<3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3 <3
*/

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:83:32: warning: comparison of integer expressions of different signedness: 'std::vector<double>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   83 |             if (srta[i].size() < k - i)
      |                 ~~~~~~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 212 KB Output is correct
5 Correct 7 ms 2756 KB Output is correct
6 Correct 21 ms 3088 KB Output is correct
7 Correct 78 ms 3900 KB Output is correct
8 Correct 182 ms 4288 KB Output is correct
9 Correct 346 ms 4764 KB Output is correct
10 Correct 163 ms 4108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 212 KB Output is correct
5 Correct 7 ms 2756 KB Output is correct
6 Correct 21 ms 3088 KB Output is correct
7 Correct 78 ms 3900 KB Output is correct
8 Correct 182 ms 4288 KB Output is correct
9 Correct 346 ms 4764 KB Output is correct
10 Correct 163 ms 4108 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 31 ms 3172 KB Output is correct
13 Correct 30 ms 3204 KB Output is correct
14 Correct 30 ms 3324 KB Output is correct
15 Correct 161 ms 4156 KB Output is correct
16 Correct 158 ms 4040 KB Output is correct
17 Correct 159 ms 4156 KB Output is correct
18 Correct 337 ms 4868 KB Output is correct
19 Correct 335 ms 4808 KB Output is correct
20 Correct 334 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 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 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
13 Correct 1 ms 328 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 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 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 0 ms 340 KB Output is correct
31 Correct 0 ms 324 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 328 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
# 결과 실행 시간 메모리 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 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 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 1 ms 212 KB Output is correct
13 Correct 1 ms 328 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 212 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Correct 0 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 0 ms 340 KB Output is correct
31 Correct 0 ms 324 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 328 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 328 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 1 ms 448 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 468 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 468 KB Output is correct
49 Correct 2 ms 452 KB Output is correct
50 Correct 2 ms 468 KB Output is correct
51 Correct 4 ms 596 KB Output is correct
52 Correct 3 ms 596 KB Output is correct
53 Correct 2 ms 468 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 2 ms 452 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 2 ms 468 KB Output is correct
58 Correct 2 ms 468 KB Output is correct
59 Correct 2 ms 468 KB Output is correct
60 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 333 ms 4848 KB Output is correct
2 Correct 337 ms 4832 KB Output is correct
3 Correct 340 ms 4916 KB Output is correct
4 Correct 356 ms 4808 KB Output is correct
5 Correct 339 ms 4844 KB Output is correct
6 Correct 343 ms 4788 KB Output is correct
7 Correct 338 ms 4912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 212 KB Output is correct
5 Correct 7 ms 2756 KB Output is correct
6 Correct 21 ms 3088 KB Output is correct
7 Correct 78 ms 3900 KB Output is correct
8 Correct 182 ms 4288 KB Output is correct
9 Correct 346 ms 4764 KB Output is correct
10 Correct 163 ms 4108 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 31 ms 3172 KB Output is correct
13 Correct 30 ms 3204 KB Output is correct
14 Correct 30 ms 3324 KB Output is correct
15 Correct 161 ms 4156 KB Output is correct
16 Correct 158 ms 4040 KB Output is correct
17 Correct 159 ms 4156 KB Output is correct
18 Correct 337 ms 4868 KB Output is correct
19 Correct 335 ms 4808 KB Output is correct
20 Correct 334 ms 4952 KB Output is correct
21 Correct 1 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 320 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 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 1 ms 212 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1 ms 212 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 324 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 0 ms 340 KB Output is correct
47 Correct 0 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 0 ms 340 KB Output is correct
51 Correct 0 ms 324 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 328 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 1 ms 328 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 448 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 468 KB Output is correct
66 Correct 1 ms 468 KB Output is correct
67 Correct 2 ms 468 KB Output is correct
68 Correct 2 ms 468 KB Output is correct
69 Correct 2 ms 452 KB Output is correct
70 Correct 2 ms 468 KB Output is correct
71 Correct 4 ms 596 KB Output is correct
72 Correct 3 ms 596 KB Output is correct
73 Correct 2 ms 468 KB Output is correct
74 Correct 2 ms 468 KB Output is correct
75 Correct 2 ms 452 KB Output is correct
76 Correct 2 ms 468 KB Output is correct
77 Correct 2 ms 468 KB Output is correct
78 Correct 2 ms 468 KB Output is correct
79 Correct 2 ms 468 KB Output is correct
80 Correct 2 ms 468 KB Output is correct
81 Correct 333 ms 4848 KB Output is correct
82 Correct 337 ms 4832 KB Output is correct
83 Correct 340 ms 4916 KB Output is correct
84 Correct 356 ms 4808 KB Output is correct
85 Correct 339 ms 4844 KB Output is correct
86 Correct 343 ms 4788 KB Output is correct
87 Correct 338 ms 4912 KB Output is correct
88 Correct 9 ms 2772 KB Output is correct
89 Correct 9 ms 2796 KB Output is correct
90 Correct 23 ms 3044 KB Output is correct
91 Correct 22 ms 3060 KB Output is correct
92 Correct 84 ms 3624 KB Output is correct
93 Correct 82 ms 3608 KB Output is correct
94 Correct 195 ms 4140 KB Output is correct
95 Correct 199 ms 4304 KB Output is correct
96 Correct 275 ms 4552 KB Output is correct
97 Correct 278 ms 4592 KB Output is correct
98 Correct 159 ms 4124 KB Output is correct
99 Correct 160 ms 4024 KB Output is correct
100 Correct 158 ms 4192 KB Output is correct
101 Correct 167 ms 4296 KB Output is correct
102 Correct 162 ms 4236 KB Output is correct
103 Correct 169 ms 4124 KB Output is correct
104 Correct 167 ms 4264 KB Output is correct
105 Correct 163 ms 4188 KB Output is correct