답안 #587146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587146 2022-07-01T11:40:52 Z rgnerdplayer Let's Win the Election (JOI22_ho_t3) C++17
0 / 100
187 ms 1384 KB
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    auto solve = [&]() {
        int n, k;
        cin >> n >> k;

        vector<int> a(n), b(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i] >> b[i];
            if (b[i] == -1) {
                b[i] = 1e6;
            }
        }

        vector<int> ord(n);
        iota(ord.begin(), ord.end(), 0);
        sort(ord.begin(), ord.end(), [&](auto i, auto j) {
            return b[i] < b[j];
        });

        vector g(n + 1, vector<int>(k + 1, 1e9));
        g[n][0] = 0;

        for (int i = n - 1; i >= 0; i--) {
            g[i] = g[i + 1];
            for (int j = 0; j < k; j++) {
                g[i][j + 1] = min(g[i][j + 1], g[i + 1][j] + a[i]);
            }
        }

        double ans = 1e9;

        for (int x = 0; x <= k; x++) {
            vector<double> f(x + 1, 1e9);
            f[0] = 0;
            for (int i = 0; i < k; i++) {
                int p = ord[i];
                vector<double> nf(x + 1, 1e9);
                for (int j = 0; j <= x; j++) {
                    nf[j] = min(nf[j], f[j] + 1.0 * a[p] / (x + 1));
                    if (j < x) {
                        nf[j + 1] = min(nf[j + 1], f[j] + 1.0 * b[p] / (j + 1));
                    }
                }
                f = nf;
                ans = min(ans, f[x] + 1.0 * g[i + 1][k - i - 1] / (x + 1));
            }
        }

        cout << fixed << setprecision(9) << ans << '\n';
    };
    
    solve();
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 316 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 316 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 187 ms 1384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 316 KB Output isn't correct
4 Halted 0 ms 0 KB -