Submission #922063

# Submission time Handle Problem Language Result Execution time Memory
922063 2024-02-05T01:15:01 Z cthbst Let's Win the Election (JOI22_ho_t3) C++14
0 / 100
1899 ms 4672 KB
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>

#define int long long
#define F first
#define S second
#define sz(v) (int)v.size()
using namespace std;

const int maxn = (int)505;
const int INF = (int)1e18 + 5;

int n, k;
pair<double, double> ar[maxn];
double dp[maxn][maxn];
double List[maxn][maxn];

double f(int s, int cnt) {
    if (s < 0 || cnt < 0) return INF;
    if (List[s][cnt] != 0) return List[s][cnt];

    vector<int> v;
    for (int i = s; i <= n; i++) {
        v.push_back(ar[i].F);
    }
    sort(v.begin(), v.end());
    if (cnt > sz(v)) return List[s][cnt] = INF;

    double rtn = 0;
    for (int i = 0; i < cnt; i++) {
        rtn += v[i];
    }

    return List[s][cnt] = rtn;
}

double myDP(int x) {
    dp[1][0] = ar[1].F / (x + 1);
    dp[1][1] = ar[1].S / 1.0;
    for (int j = 2; j <= x; j++) dp[1][j] = INF;

    for (int i = 2; i <= n; i++) {
        dp[i][0] = dp[i - 1][0] + ar[i].F / (x + 1);
        for (int j = 1; j <= x; j++) {
            if (j > i)
                dp[i][j] = INF;
            else {
                double A = dp[i - 1][j] + ar[i].F / (x + 1);
                double B = dp[i - 1][j - 1] + ar[i].S / j;
                dp[i][j] = min(A, B);
            }
        }
    }

    double rtn = INF;
    for (int i = 1; i <= n; i++) {
        rtn = min(rtn, dp[i][x] + f(i + 1, k - x) / (x + 1));
    }
    return rtn;
}

void solve() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> ar[i].F >> ar[i].S;
        if (ar[i].S == -1) ar[i].S = INF;
    }
    sort(ar + 1, ar + 1 + n, [](auto &a, auto &b) {
        if (a.S == b.S) return a.F < b.F;
        return a.S < b.S;
    });

    // cout << "ar : \n";
    // for (int i = 1; i <= n; i++) cout << ar[i].F << ' ' << ar[i].S << '\n';
    // cout << '\n';

    double an = INF;
    for (int x = 0; x <= n; x++) {
        an = min(an, myDP(x));
    }
    cout << fixed << setprecision(15) << an << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1899 ms 4672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -