제출 #1325839

#제출 시각아이디문제언어결과실행 시간메모리
1325839bbldrizzyLet's Win the Election (JOI22_ho_t3)C++20
56 / 100
2593 ms1084 KiB
#include <bits/stdc++.h>
#include <ios>
#include <iostream>
#include <set>
#include <random>
using namespace std;
using ll = double;
using P = pair<double, double>;
#define f first
#define s second
const ll MOD = 1e9+7;
const ll inf = 4*1e18;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

long long md(long long a, long long m) {
    return (a % m + m) % m;
}

int main() {
    // freopen("input.in", "r", stdin);
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll n, k; cin >> n >> k;
    vector<P> v;
    for (int i = 0; i < n; i++) {
        ll x, y; cin >> x >> y;
        v.push_back({y, x});
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        ll tmp = v[i].f;
        v[i].f = v[i].s;
        v[i].s = tmp;
    }
    ll M = 1e9;
    for (int i = 0; i <= k; i++) {
        ll coll = i;
        ll vote = k-i;
        vector<vector<ll>> dp(coll+1, vector<ll>(vote+1, 1e9));
        dp[0][0] = 0;
        for (int j = 0; j < n; j++) {
            vector<vector<ll>> ndp(coll+1, vector<ll>(vote+1, 1e9));
            ndp[0][0] = 0;
            for (int r = 0; r <= coll; r++) {
                for (int w = 0; w <= vote; w++) {
                    if (r != coll) {
                        if (w > 0) ndp[r][w] = dp[r][w-1] + v[j].f/(coll+1);
                        if (r > 0 && v[j].s != -1) ndp[r][w] = min(ndp[r][w], dp[r-1][w] + v[j].s/r);
                    } else {
                        ndp[r][w] = dp[r][w];
                        if (r > 0 && v[j].s != -1) ndp[r][w] = min(ndp[r][w], dp[r-1][w] + v[j].s/r);
                        if (w > 0) ndp[r][w] = min(ndp[r][w], dp[r][w-1] + (v[j].f)/(coll+1));
                    }
                    ndp[r][w] = min(ndp[r][w], dp[r][w]);
                }
            }
            swap(dp, ndp);
        }
        // cout << "coll, vote, dp[coll][vote]: " << coll << ", " << vote << ", " << dp[coll][vote] << "\n";
        M = min(M, dp[coll][vote]);
    }
    cout << M;
}   
#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...