Submission #532203

# Submission time Handle Problem Language Result Execution time Memory
532203 2022-03-02T13:08:37 Z Jarif_Rahman Let's Win the Election (JOI22_ho_t3) C++17
56 / 100
2500 ms 226912 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
typedef double ld;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cerr.precision(100);
    cout.precision(100);

    int n, k; cin >> n >> k;
    vector<pair<int, int>> v(n);
    for(auto &p: v) cin >> p.f >> p.sc;

    sort(v.begin(), v.end(), [](pair<ld, ld> a, pair<ld, ld> b){
        swap(a.f, a.sc);
        swap(b.f, b.sc);
        if(a.f == -1) a.f = 1e9;
        if(b.f == -1) b.f = 1e9;
        return a < b;
    });

    ld ans = 1e9;
    vector<vector<vector<ld>>> dp;

    for(int c = 0; c <= k; c++){
        dp = vector<vector<vector<ld>>>(n, vector<vector<ld>>(c+1, vector<ld>(k-c+1, 1e6)));
        for(int i = 0; i < n; i++) dp[i][0][0] = 0;
        for(int i = n-1; i >= 0; i--){
            for(int j0 = 0; j0 <= c; j0++) for(int j1 = 0; j1 <= k-c && j0+j1 <= n-i; j1++){
                if(j1+j0 == 0) continue;

                if(i == n-1){
                    if(j1 == 1) dp[i][j0][j1] = (ld)v[i].f/(ld)(c+1);
                    else if(j0 == 1 && v[i].sc != -1) dp[i][j0][j1] = (ld)v[i].sc/(ld)c;
                    continue;
                }

                dp[i][j0][j1] = dp[i+1][j0][j1];
                if(j1 != 0) dp[i][j0][j1] = min(dp[i][j0][j1], (ld)v[i].f/(ld)(c+1) + dp[i+1][j0][j1-1]);
                if(v[i].sc != -1 && j0 != 0){
                    dp[i][j0][j1] = min(dp[i][j0][j1], (ld)v[i].sc/(ld)(c-j0+1) + dp[i+1][j0-1][j1]);
                }
            }
        }
        ans = min(ans, dp[0][c][k-c]);
    }

    cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 119 ms 6668 KB Output is correct
6 Correct 1421 ms 34440 KB Output is correct
7 Execution timed out 2531 ms 115064 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 119 ms 6668 KB Output is correct
6 Correct 1421 ms 34440 KB Output is correct
7 Execution timed out 2531 ms 115064 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 280 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 280 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 312 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 308 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 312 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 280 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 308 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 312 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 308 KB Output is correct
34 Correct 1 ms 324 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 312 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 304 KB Output is correct
41 Correct 2 ms 452 KB Output is correct
42 Correct 2 ms 460 KB Output is correct
43 Correct 6 ms 820 KB Output is correct
44 Correct 6 ms 832 KB Output is correct
45 Correct 21 ms 1564 KB Output is correct
46 Correct 22 ms 1600 KB Output is correct
47 Correct 41 ms 2408 KB Output is correct
48 Correct 41 ms 2356 KB Output is correct
49 Correct 66 ms 3432 KB Output is correct
50 Correct 69 ms 3588 KB Output is correct
51 Correct 105 ms 4936 KB Output is correct
52 Correct 106 ms 4908 KB Output is correct
53 Correct 37 ms 2380 KB Output is correct
54 Correct 38 ms 2328 KB Output is correct
55 Correct 37 ms 2452 KB Output is correct
56 Correct 36 ms 2360 KB Output is correct
57 Correct 38 ms 2380 KB Output is correct
58 Correct 40 ms 2392 KB Output is correct
59 Correct 39 ms 2376 KB Output is correct
60 Correct 41 ms 2356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2570 ms 226912 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 119 ms 6668 KB Output is correct
6 Correct 1421 ms 34440 KB Output is correct
7 Execution timed out 2531 ms 115064 KB Time limit exceeded
8 Halted 0 ms 0 KB -