Submission #916895

# Submission time Handle Problem Language Result Execution time Memory
916895 2024-01-26T18:00:24 Z ace5 Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
380 ms 6540 KB
#include <bits/stdc++.h>

using namespace std;

#define int int64_t

typedef long double ld;

const int maxn = 501;

ld dp[maxn][maxn];
int pr[maxn][maxn];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(18);
    int n,k;
    cin >> n >> k;
    vector<pair<int,int>> ab(n);
    for(int i = 0;i < n;++i)
    {
        cin >> ab[i].second >> ab[i].first;
        if(ab[i].first == -1)
        {
            ab[i].first = 1e18;
        }
    }
    sort(ab.begin(),ab.end());
    for(int pos = 0;pos < n;++pos)
    {
        vector<int> cc;
        for(int j = pos;j < n;++j)
        {
            cc.push_back(ab[j].second);
        }
        sort(cc.begin(),cc.end());
        pr[pos][0] = 0;
        for(int j = 0;j < cc.size();++j)
        {
            pr[pos][j+1] = pr[pos][j] + cc[j];
        }
    }
    ld ans = 1e18;
    for(int kb = 0;kb <= k;++kb)
    {
        for(int i = n;i >= 0;--i)
        {
            for(int j = 0;j <= kb;++j)
            {
                if(i == n)
                {
                    dp[i][j] = (j == kb ? 0 : 1e18);
                }
                else if(j == kb)
                {
                    dp[i][j] = (i > k ? 1e18 : ld(pr[i][k-i])/(kb+1));
                }
                else
                {
                    dp[i][j] = min(dp[i+1][j+1]+ld(ab[i].first)/(j+1),dp[i+1][j]+ld(ab[i].second)/(kb+1));
                }
            }
        }
        ans = min(ans,dp[0][0]);
    }
    cout << ans;
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:40:25: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int j = 0;j < cc.size();++j)
      |                       ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 6 ms 5724 KB Output is correct
6 Correct 25 ms 5724 KB Output is correct
7 Correct 111 ms 6336 KB Output is correct
8 Correct 204 ms 6352 KB Output is correct
9 Correct 374 ms 6244 KB Output is correct
10 Correct 177 ms 6348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 6 ms 5724 KB Output is correct
6 Correct 25 ms 5724 KB Output is correct
7 Correct 111 ms 6336 KB Output is correct
8 Correct 204 ms 6352 KB Output is correct
9 Correct 374 ms 6244 KB Output is correct
10 Correct 177 ms 6348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 36 ms 5904 KB Output is correct
13 Correct 36 ms 5980 KB Output is correct
14 Correct 36 ms 5908 KB Output is correct
15 Correct 218 ms 6540 KB Output is correct
16 Correct 180 ms 6228 KB Output is correct
17 Correct 177 ms 6352 KB Output is correct
18 Correct 362 ms 6484 KB Output is correct
19 Correct 370 ms 6408 KB Output is correct
20 Correct 380 ms 6112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2504 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2512 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2504 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2512 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 4696 KB Output is correct
42 Correct 1 ms 4700 KB Output is correct
43 Correct 1 ms 4700 KB Output is correct
44 Correct 1 ms 4700 KB Output is correct
45 Correct 2 ms 4492 KB Output is correct
46 Correct 2 ms 4700 KB Output is correct
47 Correct 2 ms 4700 KB Output is correct
48 Correct 3 ms 4700 KB Output is correct
49 Correct 3 ms 4700 KB Output is correct
50 Correct 3 ms 4696 KB Output is correct
51 Correct 4 ms 4696 KB Output is correct
52 Correct 5 ms 4696 KB Output is correct
53 Correct 2 ms 4700 KB Output is correct
54 Correct 3 ms 4700 KB Output is correct
55 Correct 2 ms 4700 KB Output is correct
56 Correct 2 ms 4700 KB Output is correct
57 Correct 3 ms 4700 KB Output is correct
58 Correct 2 ms 4700 KB Output is correct
59 Correct 3 ms 4700 KB Output is correct
60 Correct 3 ms 4700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 360 ms 6484 KB Output is correct
2 Correct 357 ms 6136 KB Output is correct
3 Correct 360 ms 6480 KB Output is correct
4 Correct 354 ms 6264 KB Output is correct
5 Correct 364 ms 6228 KB Output is correct
6 Correct 359 ms 6168 KB Output is correct
7 Correct 363 ms 6272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 6 ms 5724 KB Output is correct
6 Correct 25 ms 5724 KB Output is correct
7 Correct 111 ms 6336 KB Output is correct
8 Correct 204 ms 6352 KB Output is correct
9 Correct 374 ms 6244 KB Output is correct
10 Correct 177 ms 6348 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 36 ms 5904 KB Output is correct
13 Correct 36 ms 5980 KB Output is correct
14 Correct 36 ms 5908 KB Output is correct
15 Correct 218 ms 6540 KB Output is correct
16 Correct 180 ms 6228 KB Output is correct
17 Correct 177 ms 6352 KB Output is correct
18 Correct 362 ms 6484 KB Output is correct
19 Correct 370 ms 6408 KB Output is correct
20 Correct 380 ms 6112 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2392 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2392 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 1 ms 2392 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2392 KB Output is correct
34 Correct 1 ms 2392 KB Output is correct
35 Correct 1 ms 2504 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 2 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2396 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 1 ms 2396 KB Output is correct
45 Correct 1 ms 2392 KB Output is correct
46 Correct 1 ms 2396 KB Output is correct
47 Correct 1 ms 2392 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2396 KB Output is correct
50 Correct 1 ms 2392 KB Output is correct
51 Correct 1 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 1 ms 2396 KB Output is correct
54 Correct 1 ms 2396 KB Output is correct
55 Correct 1 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2512 KB Output is correct
58 Correct 1 ms 2396 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 1 ms 2396 KB Output is correct
61 Correct 1 ms 4696 KB Output is correct
62 Correct 1 ms 4700 KB Output is correct
63 Correct 1 ms 4700 KB Output is correct
64 Correct 1 ms 4700 KB Output is correct
65 Correct 2 ms 4492 KB Output is correct
66 Correct 2 ms 4700 KB Output is correct
67 Correct 2 ms 4700 KB Output is correct
68 Correct 3 ms 4700 KB Output is correct
69 Correct 3 ms 4700 KB Output is correct
70 Correct 3 ms 4696 KB Output is correct
71 Correct 4 ms 4696 KB Output is correct
72 Correct 5 ms 4696 KB Output is correct
73 Correct 2 ms 4700 KB Output is correct
74 Correct 3 ms 4700 KB Output is correct
75 Correct 2 ms 4700 KB Output is correct
76 Correct 2 ms 4700 KB Output is correct
77 Correct 3 ms 4700 KB Output is correct
78 Correct 2 ms 4700 KB Output is correct
79 Correct 3 ms 4700 KB Output is correct
80 Correct 3 ms 4700 KB Output is correct
81 Correct 360 ms 6484 KB Output is correct
82 Correct 357 ms 6136 KB Output is correct
83 Correct 360 ms 6480 KB Output is correct
84 Correct 354 ms 6264 KB Output is correct
85 Correct 364 ms 6228 KB Output is correct
86 Correct 359 ms 6168 KB Output is correct
87 Correct 363 ms 6272 KB Output is correct
88 Correct 9 ms 5724 KB Output is correct
89 Correct 9 ms 5724 KB Output is correct
90 Correct 28 ms 5980 KB Output is correct
91 Correct 28 ms 5980 KB Output is correct
92 Correct 94 ms 6224 KB Output is correct
93 Correct 99 ms 6232 KB Output is correct
94 Correct 206 ms 6224 KB Output is correct
95 Correct 202 ms 6116 KB Output is correct
96 Correct 288 ms 6224 KB Output is correct
97 Correct 288 ms 6228 KB Output is correct
98 Correct 178 ms 6320 KB Output is correct
99 Correct 179 ms 6228 KB Output is correct
100 Correct 178 ms 6140 KB Output is correct
101 Correct 185 ms 6232 KB Output is correct
102 Correct 176 ms 6224 KB Output is correct
103 Correct 177 ms 6184 KB Output is correct
104 Correct 187 ms 6352 KB Output is correct
105 Correct 179 ms 6128 KB Output is correct