답안 #691297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
691297 2023-01-31T04:44:56 Z yaufung Let's Win the Election (JOI22_ho_t3) C++17
11 / 100
30 ms 2376 KB
#include <bits/stdc++.h>
using namespace std;

double solve(int n, int k, vector<pair<int, int>> &a, int totalB) {
    vector<vector<double>> dp(n + 1, vector<double>(n + 1, 1e9));
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int As = 0; As <= min(i - 1, k - totalB); As++) {
            int Bs = min(totalB, i - 1 - As);
            if (As < k - totalB) {
                double d = a[i].first;
                dp[i][As + 1] = min(dp[i][As + 1], dp[i - 1][As] + d / (totalB + 1));
            }
            if (Bs < totalB) {
                double d = a[i].second;
                dp[i][As] = min(dp[i][As], dp[i - 1][As] + d / (Bs + 1));
            }
            else {
                dp[i][As] = min(dp[i][As], dp[i - 1][As]);
            }
        }
    }
    return dp[n][k - totalB];
}

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> a(n + 1, {0, 0});
    for (int i = 1; i <= n; i++) {
        cin >> a[i].second >> a[i].first;
        if (a[i].first == -1) a[i].first = 1e9;
    }
    sort(a.begin(), a.end());
    for (int i = 1; i <= n; i++) {
        swap(a[i].first, a[i].second);
    }
    double ans = 1e9;
    int bot = 0, top = k;
    while (bot + 2 < top) {
        int m1 = (bot * 2 + top) / 3;
        int m2 = (bot + top * 2) / 3;
        double ans1 = solve(n, k, a, m1);
        double ans2 = solve(n, k, a, m2);
        ans = min(ans, min(ans1, ans2));
        if (ans1 > ans2) bot = m1;
        else top = m2;
    }
    for (int i = bot + 1; i < top; i++) {
        ans = min(ans, solve(n, k, a, i));
    }
    cout << setprecision(10) << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2376 KB Output is correct
2 Correct 25 ms 2332 KB Output is correct
3 Correct 26 ms 2364 KB Output is correct
4 Correct 28 ms 2336 KB Output is correct
5 Correct 22 ms 2328 KB Output is correct
6 Correct 26 ms 2372 KB Output is correct
7 Correct 19 ms 2364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -