Submission #534096

# Submission time Handle Problem Language Result Execution time Memory
534096 2022-03-08T01:03:26 Z balbit Let's Win the Election (JOI22_ho_t3) C++14
100 / 100
237 ms 2380 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<ll, ll>
#define f first
#define s second

#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<" "<<#__VA_ARGS__<<" - ", _do(__VA_ARGS__)
template <typename T> void _do( T && x) {cerr<<x<<endl;}
template <typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT

const int maxn = 500+5;
const ll inf = 1ll<<62;

int A[maxn], B[maxn];

double dp[maxn][maxn];
ll mnsum[maxn];

signed main(){
    ios::sync_with_stdio(0), cin.tie(0);

    bug(1,2);

    int n, k; cin>>n>>k;
    vector<pii> bo(n);
    REP(i,n) {
        cin>>bo[i].s>>bo[i].f;
        if (bo[i].f == -1) bo[i].f = inf;
    }
    sort(ALL(bo));

    REP1(i,n) {
        A[i] = bo[i-1].s; B[i] = bo[i-1].f;
        bug(i,A[i],B[i]);
    }

    vector<ll> tmp;
    for (int i = n; i>=1; --i) {
        tmp.pb(A[i]);
        int need = k-i+1;
        sort(ALL(tmp));
        REP(j, need) mnsum[i] += tmp[j];
        bug(i, mnsum[i]);
    }
    double re = mnsum[1];
    for (int TC = 1; TC <=k; ++TC) {
        // total number of collaborators + 1
        REP(i, maxn) fill(dp[i], dp[i]+maxn, inf);
        dp[0][1] = 0;
        REP1(i,n) {
            REP1(t, TC) {
                if (t>1 && B[i] != inf) MN(dp[i][t], dp[i-1][t-1] + B[i] / (double)(t-1));
                MN(dp[i][t], dp[i-1][t] +   A[i] / (double)(TC));
            }
            MN(re, dp[i][TC] + mnsum[i+1] / (double)TC);
        }
    }

    cout<<fixed<<setprecision(10)<<re<<endl;

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2300 KB Output is correct
2 Correct 1 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 2 ms 2252 KB Output is correct
5 Correct 15 ms 2336 KB Output is correct
6 Correct 28 ms 2252 KB Output is correct
7 Correct 50 ms 2252 KB Output is correct
8 Correct 91 ms 2316 KB Output is correct
9 Correct 132 ms 2252 KB Output is correct
10 Correct 113 ms 2312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2300 KB Output is correct
2 Correct 1 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 2 ms 2252 KB Output is correct
5 Correct 15 ms 2336 KB Output is correct
6 Correct 28 ms 2252 KB Output is correct
7 Correct 50 ms 2252 KB Output is correct
8 Correct 91 ms 2316 KB Output is correct
9 Correct 132 ms 2252 KB Output is correct
10 Correct 113 ms 2312 KB Output is correct
11 Correct 2 ms 2252 KB Output is correct
12 Correct 45 ms 2312 KB Output is correct
13 Correct 33 ms 2252 KB Output is correct
14 Correct 31 ms 2220 KB Output is correct
15 Correct 145 ms 2312 KB Output is correct
16 Correct 136 ms 2312 KB Output is correct
17 Correct 92 ms 2312 KB Output is correct
18 Correct 220 ms 2320 KB Output is correct
19 Correct 210 ms 2316 KB Output is correct
20 Correct 149 ms 2320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2252 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Correct 3 ms 2228 KB Output is correct
4 Correct 2 ms 2240 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 2 ms 2236 KB Output is correct
7 Correct 2 ms 2252 KB Output is correct
8 Correct 2 ms 2252 KB Output is correct
9 Correct 6 ms 2252 KB Output is correct
10 Correct 2 ms 2252 KB Output is correct
11 Correct 3 ms 2252 KB Output is correct
12 Correct 2 ms 2252 KB Output is correct
13 Correct 2 ms 2236 KB Output is correct
14 Correct 3 ms 2252 KB Output is correct
15 Correct 3 ms 2240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2252 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Correct 3 ms 2228 KB Output is correct
4 Correct 2 ms 2240 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 2 ms 2236 KB Output is correct
7 Correct 2 ms 2252 KB Output is correct
8 Correct 2 ms 2252 KB Output is correct
9 Correct 6 ms 2252 KB Output is correct
10 Correct 2 ms 2252 KB Output is correct
11 Correct 3 ms 2252 KB Output is correct
12 Correct 2 ms 2252 KB Output is correct
13 Correct 2 ms 2236 KB Output is correct
14 Correct 3 ms 2252 KB Output is correct
15 Correct 3 ms 2240 KB Output is correct
16 Correct 3 ms 2240 KB Output is correct
17 Correct 4 ms 2252 KB Output is correct
18 Correct 3 ms 2240 KB Output is correct
19 Correct 2 ms 2252 KB Output is correct
20 Correct 3 ms 2252 KB Output is correct
21 Correct 3 ms 2240 KB Output is correct
22 Correct 3 ms 2240 KB Output is correct
23 Correct 2 ms 2252 KB Output is correct
24 Correct 3 ms 2320 KB Output is correct
25 Correct 3 ms 2216 KB Output is correct
26 Correct 3 ms 2252 KB Output is correct
27 Correct 2 ms 2252 KB Output is correct
28 Correct 3 ms 2252 KB Output is correct
29 Correct 3 ms 2252 KB Output is correct
30 Correct 3 ms 2252 KB Output is correct
31 Correct 2 ms 2252 KB Output is correct
32 Correct 3 ms 2252 KB Output is correct
33 Correct 3 ms 2252 KB Output is correct
34 Correct 2 ms 2252 KB Output is correct
35 Correct 3 ms 2252 KB Output is correct
36 Correct 3 ms 2252 KB Output is correct
37 Correct 3 ms 2244 KB Output is correct
38 Correct 3 ms 2252 KB Output is correct
39 Correct 3 ms 2252 KB Output is correct
40 Correct 3 ms 2236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2252 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Correct 3 ms 2228 KB Output is correct
4 Correct 2 ms 2240 KB Output is correct
5 Correct 2 ms 2252 KB Output is correct
6 Correct 2 ms 2236 KB Output is correct
7 Correct 2 ms 2252 KB Output is correct
8 Correct 2 ms 2252 KB Output is correct
9 Correct 6 ms 2252 KB Output is correct
10 Correct 2 ms 2252 KB Output is correct
11 Correct 3 ms 2252 KB Output is correct
12 Correct 2 ms 2252 KB Output is correct
13 Correct 2 ms 2236 KB Output is correct
14 Correct 3 ms 2252 KB Output is correct
15 Correct 3 ms 2240 KB Output is correct
16 Correct 3 ms 2240 KB Output is correct
17 Correct 4 ms 2252 KB Output is correct
18 Correct 3 ms 2240 KB Output is correct
19 Correct 2 ms 2252 KB Output is correct
20 Correct 3 ms 2252 KB Output is correct
21 Correct 3 ms 2240 KB Output is correct
22 Correct 3 ms 2240 KB Output is correct
23 Correct 2 ms 2252 KB Output is correct
24 Correct 3 ms 2320 KB Output is correct
25 Correct 3 ms 2216 KB Output is correct
26 Correct 3 ms 2252 KB Output is correct
27 Correct 2 ms 2252 KB Output is correct
28 Correct 3 ms 2252 KB Output is correct
29 Correct 3 ms 2252 KB Output is correct
30 Correct 3 ms 2252 KB Output is correct
31 Correct 2 ms 2252 KB Output is correct
32 Correct 3 ms 2252 KB Output is correct
33 Correct 3 ms 2252 KB Output is correct
34 Correct 2 ms 2252 KB Output is correct
35 Correct 3 ms 2252 KB Output is correct
36 Correct 3 ms 2252 KB Output is correct
37 Correct 3 ms 2244 KB Output is correct
38 Correct 3 ms 2252 KB Output is correct
39 Correct 3 ms 2252 KB Output is correct
40 Correct 3 ms 2236 KB Output is correct
41 Correct 3 ms 2236 KB Output is correct
42 Correct 3 ms 2252 KB Output is correct
43 Correct 7 ms 2252 KB Output is correct
44 Correct 4 ms 2328 KB Output is correct
45 Correct 6 ms 2380 KB Output is correct
46 Correct 6 ms 2252 KB Output is correct
47 Correct 8 ms 2252 KB Output is correct
48 Correct 8 ms 2252 KB Output is correct
49 Correct 10 ms 2252 KB Output is correct
50 Correct 10 ms 2252 KB Output is correct
51 Correct 12 ms 2252 KB Output is correct
52 Correct 13 ms 2300 KB Output is correct
53 Correct 9 ms 2284 KB Output is correct
54 Correct 9 ms 2240 KB Output is correct
55 Correct 8 ms 2252 KB Output is correct
56 Correct 11 ms 2252 KB Output is correct
57 Correct 8 ms 2252 KB Output is correct
58 Correct 12 ms 2316 KB Output is correct
59 Correct 8 ms 2320 KB Output is correct
60 Correct 9 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 2316 KB Output is correct
2 Correct 210 ms 2320 KB Output is correct
3 Correct 221 ms 2316 KB Output is correct
4 Correct 205 ms 2320 KB Output is correct
5 Correct 189 ms 2320 KB Output is correct
6 Correct 209 ms 2312 KB Output is correct
7 Correct 237 ms 2252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2300 KB Output is correct
2 Correct 1 ms 2252 KB Output is correct
3 Correct 2 ms 2252 KB Output is correct
4 Correct 2 ms 2252 KB Output is correct
5 Correct 15 ms 2336 KB Output is correct
6 Correct 28 ms 2252 KB Output is correct
7 Correct 50 ms 2252 KB Output is correct
8 Correct 91 ms 2316 KB Output is correct
9 Correct 132 ms 2252 KB Output is correct
10 Correct 113 ms 2312 KB Output is correct
11 Correct 2 ms 2252 KB Output is correct
12 Correct 45 ms 2312 KB Output is correct
13 Correct 33 ms 2252 KB Output is correct
14 Correct 31 ms 2220 KB Output is correct
15 Correct 145 ms 2312 KB Output is correct
16 Correct 136 ms 2312 KB Output is correct
17 Correct 92 ms 2312 KB Output is correct
18 Correct 220 ms 2320 KB Output is correct
19 Correct 210 ms 2316 KB Output is correct
20 Correct 149 ms 2320 KB Output is correct
21 Correct 1 ms 2252 KB Output is correct
22 Correct 2 ms 2252 KB Output is correct
23 Correct 3 ms 2228 KB Output is correct
24 Correct 2 ms 2240 KB Output is correct
25 Correct 2 ms 2252 KB Output is correct
26 Correct 2 ms 2236 KB Output is correct
27 Correct 2 ms 2252 KB Output is correct
28 Correct 2 ms 2252 KB Output is correct
29 Correct 6 ms 2252 KB Output is correct
30 Correct 2 ms 2252 KB Output is correct
31 Correct 3 ms 2252 KB Output is correct
32 Correct 2 ms 2252 KB Output is correct
33 Correct 2 ms 2236 KB Output is correct
34 Correct 3 ms 2252 KB Output is correct
35 Correct 3 ms 2240 KB Output is correct
36 Correct 3 ms 2240 KB Output is correct
37 Correct 4 ms 2252 KB Output is correct
38 Correct 3 ms 2240 KB Output is correct
39 Correct 2 ms 2252 KB Output is correct
40 Correct 3 ms 2252 KB Output is correct
41 Correct 3 ms 2240 KB Output is correct
42 Correct 3 ms 2240 KB Output is correct
43 Correct 2 ms 2252 KB Output is correct
44 Correct 3 ms 2320 KB Output is correct
45 Correct 3 ms 2216 KB Output is correct
46 Correct 3 ms 2252 KB Output is correct
47 Correct 2 ms 2252 KB Output is correct
48 Correct 3 ms 2252 KB Output is correct
49 Correct 3 ms 2252 KB Output is correct
50 Correct 3 ms 2252 KB Output is correct
51 Correct 2 ms 2252 KB Output is correct
52 Correct 3 ms 2252 KB Output is correct
53 Correct 3 ms 2252 KB Output is correct
54 Correct 2 ms 2252 KB Output is correct
55 Correct 3 ms 2252 KB Output is correct
56 Correct 3 ms 2252 KB Output is correct
57 Correct 3 ms 2244 KB Output is correct
58 Correct 3 ms 2252 KB Output is correct
59 Correct 3 ms 2252 KB Output is correct
60 Correct 3 ms 2236 KB Output is correct
61 Correct 3 ms 2236 KB Output is correct
62 Correct 3 ms 2252 KB Output is correct
63 Correct 7 ms 2252 KB Output is correct
64 Correct 4 ms 2328 KB Output is correct
65 Correct 6 ms 2380 KB Output is correct
66 Correct 6 ms 2252 KB Output is correct
67 Correct 8 ms 2252 KB Output is correct
68 Correct 8 ms 2252 KB Output is correct
69 Correct 10 ms 2252 KB Output is correct
70 Correct 10 ms 2252 KB Output is correct
71 Correct 12 ms 2252 KB Output is correct
72 Correct 13 ms 2300 KB Output is correct
73 Correct 9 ms 2284 KB Output is correct
74 Correct 9 ms 2240 KB Output is correct
75 Correct 8 ms 2252 KB Output is correct
76 Correct 11 ms 2252 KB Output is correct
77 Correct 8 ms 2252 KB Output is correct
78 Correct 12 ms 2316 KB Output is correct
79 Correct 8 ms 2320 KB Output is correct
80 Correct 9 ms 2252 KB Output is correct
81 Correct 221 ms 2316 KB Output is correct
82 Correct 210 ms 2320 KB Output is correct
83 Correct 221 ms 2316 KB Output is correct
84 Correct 205 ms 2320 KB Output is correct
85 Correct 189 ms 2320 KB Output is correct
86 Correct 209 ms 2312 KB Output is correct
87 Correct 237 ms 2252 KB Output is correct
88 Correct 10 ms 2252 KB Output is correct
89 Correct 11 ms 2232 KB Output is correct
90 Correct 25 ms 2252 KB Output is correct
91 Correct 28 ms 2316 KB Output is correct
92 Correct 72 ms 2320 KB Output is correct
93 Correct 93 ms 2316 KB Output is correct
94 Correct 124 ms 2252 KB Output is correct
95 Correct 151 ms 2320 KB Output is correct
96 Correct 173 ms 2252 KB Output is correct
97 Correct 206 ms 2252 KB Output is correct
98 Correct 101 ms 2324 KB Output is correct
99 Correct 104 ms 2316 KB Output is correct
100 Correct 129 ms 2236 KB Output is correct
101 Correct 113 ms 2316 KB Output is correct
102 Correct 105 ms 2252 KB Output is correct
103 Correct 107 ms 2252 KB Output is correct
104 Correct 120 ms 2320 KB Output is correct
105 Correct 119 ms 2320 KB Output is correct