제출 #1302094

#제출 시각아이디문제언어결과실행 시간메모리
1302094daotuankhoiLet's Win the Election (JOI22_ho_t3)C++20
100 / 100
473 ms4416 KiB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long

#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif

template <class T> bool ckmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <class T> bool ckmin(T &a, T b) { return a > b ? (a = b, true) : false; }

#define ld long double

const int MAXN = 505;
ld dp[MAXN][MAXN];
pair<int, int> a[MAXN];
int n, k;

ld calc(int fix) {
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= k - fix; j++) {
            dp[i][j] = 1e9;
        }
    }
    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= min(i, k - fix); j++) {
            int sb = i - j - 1;
            if (j) {
                /// pick a
                ckmin(dp[i][j], dp[i - 1][j - 1] + (ld)a[i].se / (fix + 1));
            }
            ckmin(dp[i][j], dp[i - 1][j] + (sb < fix ? (ld)a[i].fi / (sb + 1) : 0));
        }
    }
    return dp[n][k - fix];
}

int main() {
    #define NAME "test"
    if (fopen(NAME".inp", "r")) {
        freopen(NAME".inp", "r", stdin);
        freopen(NAME".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i].se >> a[i].fi;
        a[i].fi = a[i].fi == -1 ? 1e9 : a[i].fi;
    }
    sort(a + 1, a + n + 1);
    ld ans = 1e9;
    for (int i = 0; i <= k; i++) ckmin(ans, calc(i));
    cout << fixed << setprecision(15) << ans << '\n';
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...