Submission #962929

# Submission time Handle Problem Language Result Execution time Memory
962929 2024-04-14T09:51:21 Z RaresFelix Let's Win the Election (JOI22_ho_t3) C++17
56 / 100
2500 ms 1048576 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ld = long double;  // or double, if TL is tight
using str = string; 
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;


int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<ii> V(n);
    for(int i = 0; i < n; ++i) {
        cin >> V[i].first >> V[i].second;
        if(V[i].second == -1) V[i].second = 1e9;
    }
    sort(all(V), [&](auto a, auto b) {
            if(a.second != b.second) return a.second < b.second;
            return a < b;
    });
    vi A(n), B(n);
    for(int i = 0; i < n; ++i) {
        A[i] = V[i].first;
        B[i] = V[i].second;
    }
    
    const ld INF = 1e18;
    vector<vector<vector<ld> > > DP(n, vector(k + 1, vector<ld>(k + 1, INF)));
    ld re = INF;
    for(int nr = 0; nr <= k; ++nr) { 
        for(int i = 0; i < n; ++i)
            for(int j = 0; j <= k; ++j)
                for(int w = 0; w <= k; ++w) DP[i][j][w] = INF;
        ld fact = 1. / ld(nr + 1);
        DP[0][1][0] = fact * A[0];
        DP[0][0][1] = B[0]; 
        DP[0][0][0] = 0.;
        for(int i = 0; i + 1 < n; ++i) {
            for(int j = 0; j <= k; ++j) //nr A
                for(int w = 0; w <= k; ++w) {
                    if(j + 1 <= k)
                        DP[i + 1][j + 1][w] = min(DP[i + 1][j + 1][w], DP[i][j][w] + fact * A[i + 1]);
                    if(w + 1 <= k)
                        DP[i + 1][j][w + 1] = min(DP[i + 1][j][w + 1], DP[i][j][w] + B[i + 1] / ld(w + 1));
                    DP[i + 1][j][w] = min(DP[i + 1][j][w], DP[i][j][w]);
                }
        }
        re = min(re, DP[n - 1][k - nr][nr]);
    }
    cout << fixed << setprecision(10) << re << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1310 ms 21860 KB Output is correct
6 Execution timed out 2562 ms 127316 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1310 ms 21860 KB Output is correct
6 Execution timed out 2562 ms 127316 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 404 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 404 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 456 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 344 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 5 ms 624 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 2 ms 528 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 456 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 452 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 404 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 456 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 456 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 344 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 4 ms 604 KB Output is correct
26 Correct 5 ms 624 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 2 ms 600 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 2 ms 528 KB Output is correct
32 Correct 2 ms 504 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 456 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 2 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 8 ms 860 KB Output is correct
42 Correct 8 ms 856 KB Output is correct
43 Correct 57 ms 1884 KB Output is correct
44 Correct 59 ms 2136 KB Output is correct
45 Correct 267 ms 4752 KB Output is correct
46 Correct 249 ms 4760 KB Output is correct
47 Correct 564 ms 7584 KB Output is correct
48 Correct 570 ms 7580 KB Output is correct
49 Correct 1057 ms 11136 KB Output is correct
50 Correct 1040 ms 11136 KB Output is correct
51 Correct 1998 ms 16988 KB Output is correct
52 Correct 2017 ms 16964 KB Output is correct
53 Correct 551 ms 7588 KB Output is correct
54 Correct 559 ms 7580 KB Output is correct
55 Correct 558 ms 7584 KB Output is correct
56 Correct 548 ms 7588 KB Output is correct
57 Correct 569 ms 7580 KB Output is correct
58 Correct 546 ms 7580 KB Output is correct
59 Correct 550 ms 7516 KB Output is correct
60 Correct 586 ms 7588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 718 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 504 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1310 ms 21860 KB Output is correct
6 Execution timed out 2562 ms 127316 KB Time limit exceeded
7 Halted 0 ms 0 KB -