Submission #1042884

# Submission time Handle Problem Language Result Execution time Memory
1042884 2024-08-03T14:00:38 Z LOLOLO Let's Win the Election (JOI22_ho_t3) C++17
11 / 100
1189 ms 10532 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

#define double ld
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 5e3 + 10;
double a[N], b[N];
double f[N][N], cost[N][N];
int order[N];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, k;
    cin >> n >> k;

    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        if (b[i] < 0)
            b[i] = 1e9;

        order[i] = i;
    }

    sort(order + 1, order + 1 + n, [&] (int x, int y) {return b[x] < b[y];});

    vector <double> lst;
    for (int i = n; i >= 1; i--) {
        lst.pb(a[order[i]]);
        sort(all(lst));
        double sum = 0;
        cost[i][0] = 0;

        for (int j = 0; j < sz(lst); j++) {
            sum += lst[j];
            cost[i][j + 1] = sum;
        }
    }

    double ans = 1e18;

    for (int num = 0; num <= k; num++) {
        for (int i = 0; i <= k; i++) {
            for (int j = 0; j <= k; j++)
                f[i][j] = 1e9;
        }

        f[0][0] = 0;

        for (int i = 1; i <= k; i++) {
            for (int j = 0; j <= i; j++) {
                f[i][j] = f[i - 1][j] + a[order[i]] / double(num + 1);

                if (j > 0) {
                    f[i][j] = min(f[i][j], f[i - 1][j - 1] + b[order[i]] / double(j));
                }

                if (j == num) {
                    int r = k - i;
                    ans = min(ans, f[i][j] + cost[i + 1][r] / double(num + 1));
                }
            }
        }
    }

    cout << fixed << setprecision(10) << ans << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1068 ms 10532 KB Output is correct
2 Correct 1072 ms 10332 KB Output is correct
3 Correct 1082 ms 10332 KB Output is correct
4 Correct 1189 ms 10524 KB Output is correct
5 Correct 1081 ms 10532 KB Output is correct
6 Correct 1068 ms 10328 KB Output is correct
7 Correct 1096 ms 10532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 344 KB Output isn't correct
4 Halted 0 ms 0 KB -