Submission #1267778

#TimeUsernameProblemLanguageResultExecution timeMemory
1267778gustavo_dLet's Win the Election (JOI22_ho_t3)C++20
67 / 100
1299 ms1010368 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double lfloat;

const int MAXN = 500;
const lfloat INF = 500000;

int a[MAXN], b[MAXN];
pair<int, int> input[MAXN];
lfloat dp[MAXN+1][MAXN+1][MAXN+1];

bool cmp(pair<int, int> i, pair<int, int> j) {
    return i.second < j.second;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    int n, K; cin >> n >> K;
    bool sub0 = true;
    for (int i=0; i<n; i++) cin >> input[i].first >> input[i].second;
    sort(input, input+n, cmp);
    for (int i=0; i<n; i++) {
        a[i] = input[i].first; b[i] = input[i].second;
        // cout << a[i] << ' ' << b[i] << endl;
        if (b[i] != -1 and b[i] != a[i]) sub0 = false;
    }
    lfloat ans = INF;
    for (int c=(sub0 ? K : 0); c<=K; c++) {
        for (int k=0; k<=K; k++) {
            for (int j=0; j<=K-c; j++) dp[0][k][j] = INF;
        }
        dp[0][0][0] = 0;
        for (int i=1; i<=n; i++) {
            // if (c == 1) cout << "i=" << i << endl;
            for (int k=0; k<=c; k++) {
                if (K == n) {
                    int j = i - k;
                    dp[i][k][j] = min(
                        ((k == 0 or b[i-1] == -1) ? INF : (dp[i-1][k-1][j] + (lfloat)b[i-1] / (lfloat)k)),
                        (j == 0 ? INF : (dp[i-1][k][j-1] + (lfloat)a[i-1] / (1 + (lfloat)c)))
                    );
                    continue;
                }
                for (int j=0; j<=K-c; j++) {
                    dp[i][k][j] = min({
                        dp[i-1][k][j],
                        ((k == 0 or b[i-1] == -1) ? INF : (dp[i-1][k-1][j] + (lfloat)b[i-1] / (lfloat)k)),
                        (j == 0 ? INF : (dp[i-1][k][j-1] + (lfloat)a[i-1] / (1 + (lfloat)c)))
                    });
                    // if (c == 1) printf("%.5Lf ", dp[i][k][j]);
                }
                // if (c == 1) printf("\n");
            }
            // if (c == 1) printf("\n\n");
        }
        ans = min(ans, dp[n][c][K-c]);
    }
    printf("%.5Lf", ans);

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...