Submission #907581

# Submission time Handle Problem Language Result Execution time Memory
907581 2024-01-15T21:46:05 Z vjudge1 Let's Win the Election (JOI22_ho_t3) C++17
66 / 100
725 ms 21528 KB
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)

#define NN 110
#define M 1000000007 // 998244353

ld dp[NN][NN][NN]; // 
vector<pl> votes;
ll n, k;
ll take;

ld rec(ll i, ll bs, ll vots) {
    if (i == n) return vots + bs >= k and bs >= take ? 0: 1e18;
    auto &DP = dp[i][bs][vots];
    if (DP != DP) {
        DP = 1e18;
        DP = min(DP, rec(i+1, bs, vots)); 
        DP = min(DP, rec(i+1, bs, vots+1) + ld(votes[i].V)/(1 + take)); 
        if (~votes[i].K) DP = min(DP, rec(i+1, bs+1, vots) + ld(votes[i].K)/(1 + bs)); 
    }
    return DP;
}

int main(){
//    freopen("a.in", "r", stdin);
//    freopen("a.out", "w", stdout);

    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(20);
    cin >> n >> k;
    votes.resize(n);
    for (auto &[b, a]: votes) {
        cin >> a >> b;
    }
    sort(A(votes));
    ld ans = 1e18;    

    for (take = 0; take <= n; take++) {
        vector<bool> eaten(n);
        ll cum = 0;
        ld time = 0;
        F(i, 0, n) if (cum < take) {
            auto &[b, _] = votes[i];
            if (b == -1) continue;
            eaten[i] = 1;
            time += ld(b)/(cum + 1);
            cum++; 
        }
        if (cum < take) continue;
        vector<ll> ungotten;
        F(i, 0, n) if (!eaten[i]) ungotten.push_back(votes[i].V);
        sort(A(ungotten));
        
        for (auto x: ungotten) if (cum < k) {
            cum++;
            time += ld(x)/(take+1);
        } 
        // cout << "WHAT " << take << " " << time << endl;
        ans = min(ans, time);

        if (n <= 100) {
            memset(dp, -1, sizeof dp);
            ans = min(ans, rec(0, 0, 0));
            
            // cout << "WTF " << ans << " " << take << " " << rec(0, 0, 0) << endl;
        }
    }

    cout << ans << endl;

}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 7 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 392 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 7 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 392 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 7 ms 21080 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 21272 KB Output is correct
2 Correct 17 ms 21084 KB Output is correct
3 Correct 12 ms 21336 KB Output is correct
4 Correct 19 ms 21084 KB Output is correct
5 Correct 18 ms 21084 KB Output is correct
6 Correct 18 ms 21084 KB Output is correct
7 Correct 21 ms 21084 KB Output is correct
8 Correct 18 ms 21288 KB Output is correct
9 Correct 19 ms 21080 KB Output is correct
10 Correct 18 ms 21084 KB Output is correct
11 Correct 18 ms 21268 KB Output is correct
12 Correct 22 ms 21336 KB Output is correct
13 Correct 20 ms 21280 KB Output is correct
14 Correct 15 ms 21084 KB Output is correct
15 Correct 19 ms 21272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 21272 KB Output is correct
2 Correct 17 ms 21084 KB Output is correct
3 Correct 12 ms 21336 KB Output is correct
4 Correct 19 ms 21084 KB Output is correct
5 Correct 18 ms 21084 KB Output is correct
6 Correct 18 ms 21084 KB Output is correct
7 Correct 21 ms 21084 KB Output is correct
8 Correct 18 ms 21288 KB Output is correct
9 Correct 19 ms 21080 KB Output is correct
10 Correct 18 ms 21084 KB Output is correct
11 Correct 18 ms 21268 KB Output is correct
12 Correct 22 ms 21336 KB Output is correct
13 Correct 20 ms 21280 KB Output is correct
14 Correct 15 ms 21084 KB Output is correct
15 Correct 19 ms 21272 KB Output is correct
16 Correct 44 ms 21084 KB Output is correct
17 Correct 45 ms 21268 KB Output is correct
18 Correct 41 ms 21084 KB Output is correct
19 Correct 49 ms 21084 KB Output is correct
20 Correct 36 ms 21084 KB Output is correct
21 Correct 32 ms 21084 KB Output is correct
22 Correct 50 ms 21080 KB Output is correct
23 Correct 40 ms 21276 KB Output is correct
24 Correct 29 ms 21080 KB Output is correct
25 Correct 51 ms 21084 KB Output is correct
26 Correct 39 ms 21084 KB Output is correct
27 Correct 43 ms 21268 KB Output is correct
28 Correct 42 ms 21084 KB Output is correct
29 Correct 42 ms 21080 KB Output is correct
30 Correct 46 ms 21276 KB Output is correct
31 Correct 41 ms 21080 KB Output is correct
32 Correct 51 ms 21084 KB Output is correct
33 Correct 43 ms 21084 KB Output is correct
34 Correct 42 ms 21396 KB Output is correct
35 Correct 42 ms 21084 KB Output is correct
36 Correct 42 ms 21268 KB Output is correct
37 Correct 49 ms 21272 KB Output is correct
38 Correct 47 ms 21084 KB Output is correct
39 Correct 45 ms 21084 KB Output is correct
40 Correct 42 ms 21276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 21272 KB Output is correct
2 Correct 17 ms 21084 KB Output is correct
3 Correct 12 ms 21336 KB Output is correct
4 Correct 19 ms 21084 KB Output is correct
5 Correct 18 ms 21084 KB Output is correct
6 Correct 18 ms 21084 KB Output is correct
7 Correct 21 ms 21084 KB Output is correct
8 Correct 18 ms 21288 KB Output is correct
9 Correct 19 ms 21080 KB Output is correct
10 Correct 18 ms 21084 KB Output is correct
11 Correct 18 ms 21268 KB Output is correct
12 Correct 22 ms 21336 KB Output is correct
13 Correct 20 ms 21280 KB Output is correct
14 Correct 15 ms 21084 KB Output is correct
15 Correct 19 ms 21272 KB Output is correct
16 Correct 44 ms 21084 KB Output is correct
17 Correct 45 ms 21268 KB Output is correct
18 Correct 41 ms 21084 KB Output is correct
19 Correct 49 ms 21084 KB Output is correct
20 Correct 36 ms 21084 KB Output is correct
21 Correct 32 ms 21084 KB Output is correct
22 Correct 50 ms 21080 KB Output is correct
23 Correct 40 ms 21276 KB Output is correct
24 Correct 29 ms 21080 KB Output is correct
25 Correct 51 ms 21084 KB Output is correct
26 Correct 39 ms 21084 KB Output is correct
27 Correct 43 ms 21268 KB Output is correct
28 Correct 42 ms 21084 KB Output is correct
29 Correct 42 ms 21080 KB Output is correct
30 Correct 46 ms 21276 KB Output is correct
31 Correct 41 ms 21080 KB Output is correct
32 Correct 51 ms 21084 KB Output is correct
33 Correct 43 ms 21084 KB Output is correct
34 Correct 42 ms 21396 KB Output is correct
35 Correct 42 ms 21084 KB Output is correct
36 Correct 42 ms 21268 KB Output is correct
37 Correct 49 ms 21272 KB Output is correct
38 Correct 47 ms 21084 KB Output is correct
39 Correct 45 ms 21084 KB Output is correct
40 Correct 42 ms 21276 KB Output is correct
41 Correct 659 ms 21280 KB Output is correct
42 Correct 600 ms 21276 KB Output is correct
43 Correct 647 ms 21272 KB Output is correct
44 Correct 481 ms 21080 KB Output is correct
45 Correct 637 ms 21332 KB Output is correct
46 Correct 516 ms 21280 KB Output is correct
47 Correct 633 ms 21084 KB Output is correct
48 Correct 467 ms 21528 KB Output is correct
49 Correct 672 ms 21280 KB Output is correct
50 Correct 465 ms 21280 KB Output is correct
51 Correct 664 ms 21080 KB Output is correct
52 Correct 548 ms 21276 KB Output is correct
53 Correct 642 ms 21292 KB Output is correct
54 Correct 645 ms 21276 KB Output is correct
55 Correct 683 ms 21280 KB Output is correct
56 Correct 619 ms 21080 KB Output is correct
57 Correct 675 ms 21280 KB Output is correct
58 Correct 725 ms 21280 KB Output is correct
59 Correct 719 ms 21280 KB Output is correct
60 Correct 668 ms 21280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 7 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 392 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 7 ms 21080 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Correct 2 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 3 ms 348 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 14 ms 21272 KB Output is correct
22 Correct 17 ms 21084 KB Output is correct
23 Correct 12 ms 21336 KB Output is correct
24 Correct 19 ms 21084 KB Output is correct
25 Correct 18 ms 21084 KB Output is correct
26 Correct 18 ms 21084 KB Output is correct
27 Correct 21 ms 21084 KB Output is correct
28 Correct 18 ms 21288 KB Output is correct
29 Correct 19 ms 21080 KB Output is correct
30 Correct 18 ms 21084 KB Output is correct
31 Correct 18 ms 21268 KB Output is correct
32 Correct 22 ms 21336 KB Output is correct
33 Correct 20 ms 21280 KB Output is correct
34 Correct 15 ms 21084 KB Output is correct
35 Correct 19 ms 21272 KB Output is correct
36 Correct 44 ms 21084 KB Output is correct
37 Correct 45 ms 21268 KB Output is correct
38 Correct 41 ms 21084 KB Output is correct
39 Correct 49 ms 21084 KB Output is correct
40 Correct 36 ms 21084 KB Output is correct
41 Correct 32 ms 21084 KB Output is correct
42 Correct 50 ms 21080 KB Output is correct
43 Correct 40 ms 21276 KB Output is correct
44 Correct 29 ms 21080 KB Output is correct
45 Correct 51 ms 21084 KB Output is correct
46 Correct 39 ms 21084 KB Output is correct
47 Correct 43 ms 21268 KB Output is correct
48 Correct 42 ms 21084 KB Output is correct
49 Correct 42 ms 21080 KB Output is correct
50 Correct 46 ms 21276 KB Output is correct
51 Correct 41 ms 21080 KB Output is correct
52 Correct 51 ms 21084 KB Output is correct
53 Correct 43 ms 21084 KB Output is correct
54 Correct 42 ms 21396 KB Output is correct
55 Correct 42 ms 21084 KB Output is correct
56 Correct 42 ms 21268 KB Output is correct
57 Correct 49 ms 21272 KB Output is correct
58 Correct 47 ms 21084 KB Output is correct
59 Correct 45 ms 21084 KB Output is correct
60 Correct 42 ms 21276 KB Output is correct
61 Correct 659 ms 21280 KB Output is correct
62 Correct 600 ms 21276 KB Output is correct
63 Correct 647 ms 21272 KB Output is correct
64 Correct 481 ms 21080 KB Output is correct
65 Correct 637 ms 21332 KB Output is correct
66 Correct 516 ms 21280 KB Output is correct
67 Correct 633 ms 21084 KB Output is correct
68 Correct 467 ms 21528 KB Output is correct
69 Correct 672 ms 21280 KB Output is correct
70 Correct 465 ms 21280 KB Output is correct
71 Correct 664 ms 21080 KB Output is correct
72 Correct 548 ms 21276 KB Output is correct
73 Correct 642 ms 21292 KB Output is correct
74 Correct 645 ms 21276 KB Output is correct
75 Correct 683 ms 21280 KB Output is correct
76 Correct 619 ms 21080 KB Output is correct
77 Correct 675 ms 21280 KB Output is correct
78 Correct 725 ms 21280 KB Output is correct
79 Correct 719 ms 21280 KB Output is correct
80 Correct 668 ms 21280 KB Output is correct
81 Incorrect 5 ms 348 KB Output isn't correct
82 Halted 0 ms 0 KB -