Submission #593690

# Submission time Handle Problem Language Result Execution time Memory
593690 2022-07-11T13:46:05 Z piOOE Let's Win the Election (JOI22_ho_t3) C++17
0 / 100
936 ms 469476 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using db = double;

const int N = 501;

db dp[N][N][N]; //id, b, a

db solved[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, K;
    cin >> n >> K;
    vector<int> a(n), b(n), oa(n), ob(n);
    int cntb = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        if (b[i] != -1) {
            cntb += 1;
        }
    }
    iota(ob.begin(), ob.end(), 0);
    sort(ob.begin(), ob.end(), [&](int i, int j) {
        if (b[i] == -1) return false;
        if (b[j] == -1) return true;
        return b[i] < b[j];
    });
    const db inf = 1e12;
    auto solve = [&](int mx) -> db {
        if (solved[mx] == 0) {
            dp[0][0][0] = 0;
            for (int j = 0; j <= mx; ++j) {
                for (int k = 0; k <= K - j; ++k) {
                    dp[0][j][k] = inf;
                }
            }
            for (int i = 1; i <= n; ++i) {
                //don't take
                for (int j = 0; j <= mx; ++j) {
                    for (int k = 0; k <= min(i, K) - j; ++k) {
                        dp[i][j][k] = dp[i - 1][j][k];
                    }
                }
                //take a
                int idx = ob[i - 1];
                for (int j = 0; j <= min(i, mx); ++j) {
                    for (int k = 1; k <= min(i, K) - j; ++k) {
                        dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k - 1] + a[idx] / db(mx + 1));
                    }
                }
                if (b[idx] != -1) {
                    for (int j = 1; j <= min(i, mx); ++j) {
                        for (int k = 0; k <= min(i, K) - j; ++k) {
                            dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j - 1][k] + b[idx] / db(j));
                        }
                    }
                }
            }
            solved[mx] = dp[n][mx][K - mx];
        }
        return solved[mx];
    };
    int r = min(K, cntb);
    int x = 0;
    for (int k = 10; k > -1; --k) {
        db ansL = (x >= (1 << k) ? solve(x - (1 << k)) : inf);
        db ans = solve(x);
        db ansR = (x + (1 << k) <= r ? solve(x + (1 << k)) : inf);
        if (ansL <= ans && ansL <= ansR) {
            x -= (1 << k);
        } else if (ansR <= ans) {
            x += (1 << k);
        }
    }
    cout << fixed << setprecision(3) << solve(x);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 936 ms 469476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -