Submission #682137

# Submission time Handle Problem Language Result Execution time Memory
682137 2023-01-15T22:18:50 Z sysia Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
1173 ms 4736 KB
//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define int long long
typedef pair<int, int> T;
typedef long double ld;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;
 
void solve(){
    int n, k; cin >> n >> k;
    vector<T>tab;
    int cnt = 0;
    tab.emplace_back(-oo, -oo);
    for (int i = 1; i<=n; i++){
        int x, y; cin >> x >> y;
        if (y == -1) y = oo2;
        else cnt++;
        tab.emplace_back(x, y);
    }
    sort(tab.begin(), tab.end(),[](auto x, auto y){return x.second == y.second ? x.first < y.first : x.second < y.second;});
    ld ans = oo;
    //dp[i][j] - min wynik, gdzie j - (dla ustalonego col) = ile mi glosow brakuje (innych niz col) do k?
    for (int col = 0; col <= min(k, cnt); col++){
        vector dp(n+2, vector<ld>(n+2, oo));
        dp[0][0] = 0;
        for (int i = 1; i<=n; i++){
            auto [a, b] = tab[i];
            for (int j = 0; j <= i; j++){
                dp[i][j] = min( (j ? dp[i-1][j-1] + (ld)(a)/(ld)(col+1) : (ld)oo),
                                (j != i && i-j <= col ? dp[i-1][j] + (ld)(b)/(ld)(i-j) : dp[i-1][j])
                                );
                // debug(i, ck, dp[i][ck]);
            }
        }
        ans = min(ans, dp[n][k-col]);
    }
    cout << fixed << setprecision(17) << ans << "\n";
}
 
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    solve();
 
    return 0;
}
# 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 1 ms 212 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 3 ms 4180 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Correct 4 ms 4180 KB Output is correct
10 Correct 3 ms 4180 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 1 ms 212 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 3 ms 4180 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Correct 4 ms 4180 KB Output is correct
10 Correct 3 ms 4180 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 397 ms 4524 KB Output is correct
13 Correct 367 ms 4488 KB Output is correct
14 Correct 235 ms 4372 KB Output is correct
15 Correct 759 ms 4472 KB Output is correct
16 Correct 664 ms 4628 KB Output is correct
17 Correct 226 ms 4468 KB Output is correct
18 Correct 1142 ms 4576 KB Output is correct
19 Correct 666 ms 4600 KB Output is correct
20 Correct 241 ms 4388 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
5 Correct 1 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 1 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 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
5 Correct 1 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 1 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 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 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 212 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 212 KB Output is correct
22 Correct 1 ms 216 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 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 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 316 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 212 KB Output is correct
40 Correct 0 ms 316 KB Output is correct
# Verdict Execution time Memory 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 0 ms 212 KB Output is correct
5 Correct 1 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 1 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 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 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 212 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 212 KB Output is correct
22 Correct 1 ms 216 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 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 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 316 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 212 KB Output is correct
40 Correct 0 ms 316 KB Output is correct
41 Correct 2 ms 488 KB Output is correct
42 Correct 2 ms 488 KB Output is correct
43 Correct 2 ms 484 KB Output is correct
44 Correct 3 ms 484 KB Output is correct
45 Correct 4 ms 484 KB Output is correct
46 Correct 4 ms 492 KB Output is correct
47 Correct 5 ms 492 KB Output is correct
48 Correct 5 ms 484 KB Output is correct
49 Correct 6 ms 492 KB Output is correct
50 Correct 6 ms 484 KB Output is correct
51 Correct 7 ms 492 KB Output is correct
52 Correct 6 ms 492 KB Output is correct
53 Correct 5 ms 484 KB Output is correct
54 Correct 5 ms 476 KB Output is correct
55 Correct 5 ms 488 KB Output is correct
56 Correct 5 ms 484 KB Output is correct
57 Correct 5 ms 484 KB Output is correct
58 Correct 5 ms 484 KB Output is correct
59 Correct 5 ms 484 KB Output is correct
60 Correct 5 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1173 ms 4444 KB Output is correct
2 Correct 1129 ms 4576 KB Output is correct
3 Correct 1118 ms 4440 KB Output is correct
4 Correct 1115 ms 4688 KB Output is correct
5 Correct 1124 ms 4556 KB Output is correct
6 Correct 1155 ms 4736 KB Output is correct
7 Correct 1137 ms 4428 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 1 ms 212 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 3 ms 4180 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Correct 4 ms 4180 KB Output is correct
10 Correct 3 ms 4180 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 397 ms 4524 KB Output is correct
13 Correct 367 ms 4488 KB Output is correct
14 Correct 235 ms 4372 KB Output is correct
15 Correct 759 ms 4472 KB Output is correct
16 Correct 664 ms 4628 KB Output is correct
17 Correct 226 ms 4468 KB Output is correct
18 Correct 1142 ms 4576 KB Output is correct
19 Correct 666 ms 4600 KB Output is correct
20 Correct 241 ms 4388 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 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 1 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 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 316 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 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 216 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 320 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 320 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 1 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 1 ms 316 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 212 KB Output is correct
60 Correct 0 ms 316 KB Output is correct
61 Correct 2 ms 488 KB Output is correct
62 Correct 2 ms 488 KB Output is correct
63 Correct 2 ms 484 KB Output is correct
64 Correct 3 ms 484 KB Output is correct
65 Correct 4 ms 484 KB Output is correct
66 Correct 4 ms 492 KB Output is correct
67 Correct 5 ms 492 KB Output is correct
68 Correct 5 ms 484 KB Output is correct
69 Correct 6 ms 492 KB Output is correct
70 Correct 6 ms 484 KB Output is correct
71 Correct 7 ms 492 KB Output is correct
72 Correct 6 ms 492 KB Output is correct
73 Correct 5 ms 484 KB Output is correct
74 Correct 5 ms 476 KB Output is correct
75 Correct 5 ms 488 KB Output is correct
76 Correct 5 ms 484 KB Output is correct
77 Correct 5 ms 484 KB Output is correct
78 Correct 5 ms 484 KB Output is correct
79 Correct 5 ms 484 KB Output is correct
80 Correct 5 ms 484 KB Output is correct
81 Correct 1173 ms 4444 KB Output is correct
82 Correct 1129 ms 4576 KB Output is correct
83 Correct 1118 ms 4440 KB Output is correct
84 Correct 1115 ms 4688 KB Output is correct
85 Correct 1124 ms 4556 KB Output is correct
86 Correct 1155 ms 4736 KB Output is correct
87 Correct 1137 ms 4428 KB Output is correct
88 Correct 114 ms 4460 KB Output is correct
89 Correct 133 ms 4404 KB Output is correct
90 Correct 278 ms 4496 KB Output is correct
91 Correct 287 ms 4412 KB Output is correct
92 Correct 576 ms 4564 KB Output is correct
93 Correct 561 ms 4592 KB Output is correct
94 Correct 808 ms 4420 KB Output is correct
95 Correct 808 ms 4476 KB Output is correct
96 Correct 1016 ms 4564 KB Output is correct
97 Correct 1000 ms 4540 KB Output is correct
98 Correct 861 ms 4596 KB Output is correct
99 Correct 758 ms 4636 KB Output is correct
100 Correct 830 ms 4676 KB Output is correct
101 Correct 902 ms 4684 KB Output is correct
102 Correct 824 ms 4520 KB Output is correct
103 Correct 778 ms 4536 KB Output is correct
104 Correct 769 ms 4504 KB Output is correct
105 Correct 869 ms 4628 KB Output is correct