Submission #907583

#TimeUsernameProblemLanguageResultExecution timeMemory
907583vjudge1Let's Win the Election (JOI22_ho_t3)C++17
77 / 100
1192 ms23380 KiB
#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

vector<pl> votes;
ll n, k;
ll take;

ld dp[NN][NN][NN]; // 


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;
}

#define SN 510

namespace keqn {

    ld dp[SN][SN]; // 

    ld rec(ll i, ll bs) {
        if (i == n) return bs >= take ? 0: 1e18;
        auto &DP = dp[i][bs];
        if (DP != DP) {
            DP = 1e18;
            DP = min(DP, rec(i+1, bs) + ld(votes[i].V)/(1 + take)); 
            if (~votes[i].K) DP = min(DP, rec(i+1, bs+1) + 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; 

    if (k == n) {
        for (take = 0; take <= n; ++take) {
            memset(keqn::dp, -1, sizeof(keqn::dp));
            ans = min(ans, keqn::rec(0, 0));
        }
        cout << ans << '\n';
        return 0;
    }   

    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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...