답안 #641111

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641111 2022-09-16T02:15:05 Z cthbst Let's Win the Election (JOI22_ho_t3) C++14
10 / 100
844 ms 8360 KB
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

#define int long long
using pii = pair<int, int>;

const long double INF = 1e18;
const int maxn = 505;

int n, k;
vector<pii> vc;
long double dp[maxn][maxn];
long double sf[maxn][maxn];  // sf[i][j] 從 A[i~(n-1)] 選 j 個最大的數字

bool cmp(pii a, pii b) {
    if (a.second == -1 && b.second == -1) {
        return a.first < b.first;
    }
    if (a.second == -1 || b.second == -1) {
        return a.second > b.second;
    }
    return a.second < b.second;
}

void build_sf() {
    for (int i = 0; i < maxn; i++) {
        fill(sf[i] + 1, sf[i] + maxn, INF);
    }

    for (int i = n - 1; i >= 0; i--) {
        vector<int> cur;
        for (int j = i; j < n; j++) {
            cur.push_back(vc[j].first);
        }
        sort(cur.begin(), cur.end());
        for (int j = 1; j <= k; j++) {
            if (j > (int)(cur.size()))
                break;
            else
                sf[i][j] = sf[i][j - 1] + cur[j - 1];
        }
    }
}

long double solve(const int t) {
    for (int i = 0; i < n; i++) {
        fill(dp[i], dp[i] + (t + 1), INF);
    }

    for (int i = 0; i < n; i++) {
        if (vc[i].second == -1) break;

        if (i == 0) {
            dp[i][0] = vc[i].first / (t + 1.0);
            dp[i][1] = vc[i].second;
            continue;
        }
        for (int j = 0; j <= t; j++) {
            if (j == 0) {
                dp[i][0] = dp[i - 1][0] + vc[i].first / (t + 1.0);
            } else {
                long double x = dp[i - 1][j] + vc[i].first / (t + 1.0);
                long double y = dp[i - 1][j - 1] + vc[i].second * 1.0 / j;
                dp[i][j] = min(x, y);
            }
        }
    }
    long double res = sf[0][k];
    for (int i = t - 1; i < n; i++) {
        if (i + 1 < t) continue;
        if (n - (i + 1) < k - t) continue;
        res = min(res, dp[i][t] + sf[i + 1][k - t] / (t + 1.0));
    }
    return res;
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        vc.push_back({x, y});
    }
    sort(vc.begin(), vc.end(), cmp);
    /*
    for (int i = 0; i < n; i++) {
        cout << vc[i].first << '\t' << vc[i].second << '\n';
    }
    */

    build_sf();

    long double res = sf[0][k];
    for (int t = (1); t < (k + 1); t++) {
        res = min(res, solve(t));
    }
    cout << res << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4308 KB Output is correct
2 Correct 4 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 4 ms 4308 KB Output is correct
5 Correct 12 ms 6612 KB Output is correct
6 Correct 32 ms 7252 KB Output is correct
7 Correct 101 ms 8264 KB Output is correct
8 Correct 207 ms 8276 KB Output is correct
9 Correct 372 ms 8272 KB Output is correct
10 Correct 185 ms 8360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4308 KB Output is correct
2 Correct 4 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 4 ms 4308 KB Output is correct
5 Correct 12 ms 6612 KB Output is correct
6 Correct 32 ms 7252 KB Output is correct
7 Correct 101 ms 8264 KB Output is correct
8 Correct 207 ms 8276 KB Output is correct
9 Correct 372 ms 8272 KB Output is correct
10 Correct 185 ms 8360 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 78 ms 7448 KB Output is correct
13 Correct 75 ms 7356 KB Output is correct
14 Correct 51 ms 7372 KB Output is correct
15 Correct 381 ms 8348 KB Output is correct
16 Correct 300 ms 8224 KB Output is correct
17 Correct 249 ms 8252 KB Output is correct
18 Correct 812 ms 8272 KB Output is correct
19 Correct 607 ms 8268 KB Output is correct
20 Correct 465 ms 8248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 3 ms 4344 KB Output is correct
3 Correct 4 ms 4308 KB Output is correct
4 Correct 4 ms 4432 KB Output is correct
5 Correct 4 ms 4308 KB Output is correct
6 Correct 4 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Incorrect 3 ms 4308 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 3 ms 4344 KB Output is correct
3 Correct 4 ms 4308 KB Output is correct
4 Correct 4 ms 4432 KB Output is correct
5 Correct 4 ms 4308 KB Output is correct
6 Correct 4 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Incorrect 3 ms 4308 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Correct 3 ms 4344 KB Output is correct
3 Correct 4 ms 4308 KB Output is correct
4 Correct 4 ms 4432 KB Output is correct
5 Correct 4 ms 4308 KB Output is correct
6 Correct 4 ms 4308 KB Output is correct
7 Correct 4 ms 4308 KB Output is correct
8 Correct 4 ms 4308 KB Output is correct
9 Incorrect 3 ms 4308 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 844 ms 8272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4308 KB Output is correct
2 Correct 4 ms 4308 KB Output is correct
3 Correct 3 ms 4308 KB Output is correct
4 Correct 4 ms 4308 KB Output is correct
5 Correct 12 ms 6612 KB Output is correct
6 Correct 32 ms 7252 KB Output is correct
7 Correct 101 ms 8264 KB Output is correct
8 Correct 207 ms 8276 KB Output is correct
9 Correct 372 ms 8272 KB Output is correct
10 Correct 185 ms 8360 KB Output is correct
11 Correct 3 ms 4308 KB Output is correct
12 Correct 78 ms 7448 KB Output is correct
13 Correct 75 ms 7356 KB Output is correct
14 Correct 51 ms 7372 KB Output is correct
15 Correct 381 ms 8348 KB Output is correct
16 Correct 300 ms 8224 KB Output is correct
17 Correct 249 ms 8252 KB Output is correct
18 Correct 812 ms 8272 KB Output is correct
19 Correct 607 ms 8268 KB Output is correct
20 Correct 465 ms 8248 KB Output is correct
21 Correct 3 ms 4308 KB Output is correct
22 Correct 3 ms 4344 KB Output is correct
23 Correct 4 ms 4308 KB Output is correct
24 Correct 4 ms 4432 KB Output is correct
25 Correct 4 ms 4308 KB Output is correct
26 Correct 4 ms 4308 KB Output is correct
27 Correct 4 ms 4308 KB Output is correct
28 Correct 4 ms 4308 KB Output is correct
29 Incorrect 3 ms 4308 KB Output isn't correct
30 Halted 0 ms 0 KB -