Submission #745719

#TimeUsernameProblemLanguageResultExecution timeMemory
745719nguyentunglamLet's Win the Election (JOI22_ho_t3)C++17
21 / 100
821 ms5456 KiB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 510;
pair<int, int> a[N];
int g[N][N];
long double f[N][N];
int main() {
    #define task ""
    cin.tie(0) -> sync_with_stdio(0);
    if (fopen ("task.inp", "r")) {
        freopen ("task.inp", "r", stdin);
        freopen ("task.out", "w", stdout);
    }
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int n, k; cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i].fi >> a[i].se;
        if (a[i].se == -1) a[i].se = 1e9;
    }
    sort(a + 1, a + n + 1, [] (const ii &x, const ii &y) {
         if (x.se != y.se) return x.se < y.se;
         return x.fi < y.fi;
         });
     long double res = 1e9;
     for(int j = 1; j <= n; j++) g[n + 1][j] = 1e9, f[0][j] = 1e9;
     for(int i = n; i >= 1; i--) {
        g[i][0] = g[i + 1][0];
        for(int j = 1; j <= n; j++) g[i][j] = min(g[i + 1][j], g[i + 1][j - 1] + a[i].fi);
     }
     for(int cnt = 0; cnt <= k; cnt++) {
        for(int i = 1; i <= n; i++) {
            f[i][0] = f[i - 1][0] + 1.0 * a[i].fi / (cnt + 1);
            for(int j = 1; j <= n; j++) {
                f[i][j] = min(f[i - 1][j] + 1.0 * a[i].fi / (cnt + 1), f[i - 1][j - 1] + 1.0 * a[i].se / j);
            }
        }
        for(int i = 1; i <= k; i++) {
            res = min(res, f[i][cnt] + 1.0 * g[i + 1][k - i] / (cnt + 1));
        }
     }
     cout << fixed << setprecision(10) << res;
}

Compilation message (stderr)

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