Submission #922727

# Submission time Handle Problem Language Result Execution time Memory
922727 2024-02-06T04:37:24 Z GrindMachine Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
1040 ms 2648 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
 
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
 
template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}
 
template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
 
/*
 
 
 
*/
 
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
 
void solve(int test_case)
{
    ll n,k; cin >> n >> k;
    vector<pll> a(n);
    rep(i,n) cin >> a[i].ff >> a[i].ss;
    rep(i,n) if(a[i].ss == -1) a[i].ss = inf2;
 
    auto cmp = [&](pll p1, pll p2){
        return p1.ss < p2.ss;
    };
 
    sort(all(a),cmp);

    ll sum[n+5][n+5];
    memset(sum,0x3f,sizeof sum);
    sum[n][0] = 0;

    rev(i,n-1,0){
        sum[i][0] = 0;
        rep1(j,n){
            sum[i][j] = min(sum[i+1][j],sum[i+1][j-1]+a[i].ff);
        }
    }

    ld ans = inf2;
    amin(ans,(ld)sum[0][k]);

    vector<ld> dp1(n+5,inf2), dp2(n+5,inf2);

    rep1(cnt,n){
        fill(all(dp1),inf2);
        dp1[0] = 0;

        rep(i,n){
            fill(all(dp2),inf2);
            rep(guys,i+1){
                // vote
                amin(dp2[guys],dp1[guys]+(ld)a[i].ff/(cnt+1));

                // collab
                amin(dp2[guys+1],dp1[guys]+(ld)a[i].ss/(guys+1));
            }

            dp1 = dp2;

            ll votes = i+1;
            if(votes >= k){
                amin(ans,dp1[cnt]);
            }
            else{
                ll more = k-votes;
                amin(ans,dp1[cnt]+(ld)sum[i+1][more]/(cnt+1));
            }
        }
    }
 
    cout << fixed << setprecision(11);
    cout << ans << endl;
}
 
int main()
{
    fastio;
 
    int t = 1;
    // cin >> t;
 
    rep1(i, t) {
        solve(i);
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1022 ms 2448 KB Output is correct
6 Correct 1036 ms 2448 KB Output is correct
7 Correct 1037 ms 2448 KB Output is correct
8 Correct 1030 ms 2396 KB Output is correct
9 Correct 994 ms 2448 KB Output is correct
10 Correct 1026 ms 2448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1022 ms 2448 KB Output is correct
6 Correct 1036 ms 2448 KB Output is correct
7 Correct 1037 ms 2448 KB Output is correct
8 Correct 1030 ms 2396 KB Output is correct
9 Correct 994 ms 2448 KB Output is correct
10 Correct 1026 ms 2448 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1018 ms 2444 KB Output is correct
13 Correct 1034 ms 2452 KB Output is correct
14 Correct 1016 ms 2452 KB Output is correct
15 Correct 1004 ms 2392 KB Output is correct
16 Correct 1006 ms 2396 KB Output is correct
17 Correct 1037 ms 2452 KB Output is correct
18 Correct 1004 ms 2392 KB Output is correct
19 Correct 1036 ms 2644 KB Output is correct
20 Correct 1000 ms 2448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 9 ms 348 KB Output is correct
42 Correct 9 ms 348 KB Output is correct
43 Correct 9 ms 536 KB Output is correct
44 Correct 9 ms 344 KB Output is correct
45 Correct 9 ms 540 KB Output is correct
46 Correct 9 ms 544 KB Output is correct
47 Correct 9 ms 348 KB Output is correct
48 Correct 9 ms 348 KB Output is correct
49 Correct 9 ms 348 KB Output is correct
50 Correct 9 ms 536 KB Output is correct
51 Correct 9 ms 536 KB Output is correct
52 Correct 9 ms 348 KB Output is correct
53 Correct 9 ms 348 KB Output is correct
54 Correct 9 ms 348 KB Output is correct
55 Correct 9 ms 348 KB Output is correct
56 Correct 9 ms 344 KB Output is correct
57 Correct 9 ms 344 KB Output is correct
58 Correct 9 ms 348 KB Output is correct
59 Correct 9 ms 348 KB Output is correct
60 Correct 9 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1016 ms 2448 KB Output is correct
2 Correct 994 ms 2444 KB Output is correct
3 Correct 997 ms 2644 KB Output is correct
4 Correct 1020 ms 2640 KB Output is correct
5 Correct 993 ms 2452 KB Output is correct
6 Correct 1033 ms 2452 KB Output is correct
7 Correct 999 ms 2452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1022 ms 2448 KB Output is correct
6 Correct 1036 ms 2448 KB Output is correct
7 Correct 1037 ms 2448 KB Output is correct
8 Correct 1030 ms 2396 KB Output is correct
9 Correct 994 ms 2448 KB Output is correct
10 Correct 1026 ms 2448 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1018 ms 2444 KB Output is correct
13 Correct 1034 ms 2452 KB Output is correct
14 Correct 1016 ms 2452 KB Output is correct
15 Correct 1004 ms 2392 KB Output is correct
16 Correct 1006 ms 2396 KB Output is correct
17 Correct 1037 ms 2452 KB Output is correct
18 Correct 1004 ms 2392 KB Output is correct
19 Correct 1036 ms 2644 KB Output is correct
20 Correct 1000 ms 2448 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 1 ms 344 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 9 ms 348 KB Output is correct
62 Correct 9 ms 348 KB Output is correct
63 Correct 9 ms 536 KB Output is correct
64 Correct 9 ms 344 KB Output is correct
65 Correct 9 ms 540 KB Output is correct
66 Correct 9 ms 544 KB Output is correct
67 Correct 9 ms 348 KB Output is correct
68 Correct 9 ms 348 KB Output is correct
69 Correct 9 ms 348 KB Output is correct
70 Correct 9 ms 536 KB Output is correct
71 Correct 9 ms 536 KB Output is correct
72 Correct 9 ms 348 KB Output is correct
73 Correct 9 ms 348 KB Output is correct
74 Correct 9 ms 348 KB Output is correct
75 Correct 9 ms 348 KB Output is correct
76 Correct 9 ms 344 KB Output is correct
77 Correct 9 ms 344 KB Output is correct
78 Correct 9 ms 348 KB Output is correct
79 Correct 9 ms 348 KB Output is correct
80 Correct 9 ms 348 KB Output is correct
81 Correct 1016 ms 2448 KB Output is correct
82 Correct 994 ms 2444 KB Output is correct
83 Correct 997 ms 2644 KB Output is correct
84 Correct 1020 ms 2640 KB Output is correct
85 Correct 993 ms 2452 KB Output is correct
86 Correct 1033 ms 2452 KB Output is correct
87 Correct 999 ms 2452 KB Output is correct
88 Correct 997 ms 2448 KB Output is correct
89 Correct 1008 ms 2448 KB Output is correct
90 Correct 1000 ms 2248 KB Output is correct
91 Correct 1022 ms 2644 KB Output is correct
92 Correct 1006 ms 2452 KB Output is correct
93 Correct 1040 ms 2448 KB Output is correct
94 Correct 1016 ms 2448 KB Output is correct
95 Correct 1004 ms 2648 KB Output is correct
96 Correct 1016 ms 2468 KB Output is correct
97 Correct 1006 ms 2644 KB Output is correct
98 Correct 996 ms 2448 KB Output is correct
99 Correct 1004 ms 2456 KB Output is correct
100 Correct 1004 ms 2464 KB Output is correct
101 Correct 994 ms 2640 KB Output is correct
102 Correct 994 ms 2456 KB Output is correct
103 Correct 1038 ms 2640 KB Output is correct
104 Correct 994 ms 2456 KB Output is correct
105 Correct 991 ms 2392 KB Output is correct