답안 #825867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
825867 2023-08-15T08:57:10 Z vjudge1 Let's Win the Election (JOI22_ho_t3) C++17
77 / 100
1101 ms 8628 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

const int N = 500;
const ld INF = 1e16;

int n, k;
pair<ld, ld> c[N + 10];
bool is1Subtask = 1;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> c[i].first >> c[i].second;
        if(c[i].second == -1) c[i].second = INF;
        is1Subtask &= (c[i].second == c[i].first || c[i].second == INF);
    }
    sort(c + 1, c + n + 1, [](pair<ld, ld> x, pair<ld, ld> y) {return x.second < y.second;});
    if(is1Subtask) {
        vector<vector<ld>> dp(n + 1, vector<ld>(n + 1, INF));
        dp[0][1] = 0;
        for(int i = 1; i <= n; i++) {
            vector<vector<ld>> newdp = dp;
            for(int k = 1; k <= i; k++) {
                for(int v = 1; v <= i + 1; v++) {
                    newdp[k][v] = min(newdp[k][v], dp[k - 1][v] + c[i].first / v); 
                    if(v > 1 && c[i].second != INF) 
                        newdp[k][v] = min(newdp[k][v], dp[k - 1][v - 1] + c[i].second / (v - 1)) ;
                }
            }
            dp = newdp;
        }
        ld res = INF;
        for(int v = 1; v <= n; v++) {
            res = min(res, dp[k][v]);
        }
        cout << setprecision(9) << fixed << res ;
        return 0;
    }
    if(n <= 100) {
        ld ans = INF; 
        for(int t = 0; t <= k; t++) {
            vector<vector<ld>> dp(t + 1, vector<ld>(k - t + 1, INF));
            dp[0][0] = 0;
            for(int i = 1; i <= n; i++) {
                vector<vector<ld>> newdp = dp;
                for(int j = 0; j <= t; j++) {
                    for(int l = 0; l <= k - t; l++) {
                        if(j) newdp[j][l] = min(newdp[j][l], dp[j - 1][l] + c[i].second / j);
                        if(l) newdp[j][l] = min(newdp[j][l], dp[j][l - 1] + c[i].first / (t + 1));
                    }
                }
                dp = newdp;
            }
            ans = min(ans, dp[t][k - t]);
        }
        cout << setprecision(9) << fixed << ans ;
        return 0;
    }
    if(n == k) {
        ld res = INF;
        for(int t = 0; t <= n; t++) {
            vector<ld> dp(t + 1, INF);
            dp[0] = 0;
            for(int i = 1; i <= n; i++) {
                vector<ld> newdp(t + 1, INF);
                for(int j = 0; j <= t; j++) {
                    newdp[j] = min(newdp[j], dp[j] + c[i].first / (t + 1));
                    if(j) newdp[j] = min(newdp[j], dp[j - 1] + c[i].second / j);
                }
                dp = newdp;
            }
            res = min(res, dp[t]);
        }
        cout << setprecision(9) << fixed << res ;
        return 0;
    }
}  
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 861 ms 8492 KB Output is correct
6 Correct 935 ms 8448 KB Output is correct
7 Correct 934 ms 8500 KB Output is correct
8 Correct 868 ms 8476 KB Output is correct
9 Correct 860 ms 8540 KB Output is correct
10 Correct 905 ms 8568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 861 ms 8492 KB Output is correct
6 Correct 935 ms 8448 KB Output is correct
7 Correct 934 ms 8500 KB Output is correct
8 Correct 868 ms 8476 KB Output is correct
9 Correct 860 ms 8540 KB Output is correct
10 Correct 905 ms 8568 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1043 ms 8504 KB Output is correct
13 Correct 961 ms 8428 KB Output is correct
14 Correct 884 ms 8516 KB Output is correct
15 Correct 1073 ms 8508 KB Output is correct
16 Correct 929 ms 8628 KB Output is correct
17 Correct 892 ms 8476 KB Output is correct
18 Correct 1101 ms 8588 KB Output is correct
19 Correct 932 ms 8496 KB Output is correct
20 Correct 927 ms 8464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 3 ms 332 KB Output is correct
42 Correct 3 ms 316 KB Output is correct
43 Correct 9 ms 340 KB Output is correct
44 Correct 10 ms 384 KB Output is correct
45 Correct 33 ms 472 KB Output is correct
46 Correct 33 ms 468 KB Output is correct
47 Correct 69 ms 560 KB Output is correct
48 Correct 75 ms 592 KB Output is correct
49 Correct 131 ms 460 KB Output is correct
50 Correct 127 ms 552 KB Output is correct
51 Correct 241 ms 500 KB Output is correct
52 Correct 241 ms 600 KB Output is correct
53 Correct 70 ms 568 KB Output is correct
54 Correct 80 ms 568 KB Output is correct
55 Correct 76 ms 572 KB Output is correct
56 Correct 72 ms 524 KB Output is correct
57 Correct 76 ms 548 KB Output is correct
58 Correct 73 ms 552 KB Output is correct
59 Correct 79 ms 576 KB Output is correct
60 Correct 75 ms 516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 797 ms 540 KB Output is correct
2 Correct 778 ms 416 KB Output is correct
3 Correct 789 ms 412 KB Output is correct
4 Correct 769 ms 412 KB Output is correct
5 Correct 814 ms 408 KB Output is correct
6 Correct 773 ms 420 KB Output is correct
7 Correct 810 ms 416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 861 ms 8492 KB Output is correct
6 Correct 935 ms 8448 KB Output is correct
7 Correct 934 ms 8500 KB Output is correct
8 Correct 868 ms 8476 KB Output is correct
9 Correct 860 ms 8540 KB Output is correct
10 Correct 905 ms 8568 KB Output is correct
11 Correct 0 ms 328 KB Output is correct
12 Correct 1043 ms 8504 KB Output is correct
13 Correct 961 ms 8428 KB Output is correct
14 Correct 884 ms 8516 KB Output is correct
15 Correct 1073 ms 8508 KB Output is correct
16 Correct 929 ms 8628 KB Output is correct
17 Correct 892 ms 8476 KB Output is correct
18 Correct 1101 ms 8588 KB Output is correct
19 Correct 932 ms 8496 KB Output is correct
20 Correct 927 ms 8464 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 324 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 320 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 1 ms 340 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 324 KB Output is correct
61 Correct 3 ms 332 KB Output is correct
62 Correct 3 ms 316 KB Output is correct
63 Correct 9 ms 340 KB Output is correct
64 Correct 10 ms 384 KB Output is correct
65 Correct 33 ms 472 KB Output is correct
66 Correct 33 ms 468 KB Output is correct
67 Correct 69 ms 560 KB Output is correct
68 Correct 75 ms 592 KB Output is correct
69 Correct 131 ms 460 KB Output is correct
70 Correct 127 ms 552 KB Output is correct
71 Correct 241 ms 500 KB Output is correct
72 Correct 241 ms 600 KB Output is correct
73 Correct 70 ms 568 KB Output is correct
74 Correct 80 ms 568 KB Output is correct
75 Correct 76 ms 572 KB Output is correct
76 Correct 72 ms 524 KB Output is correct
77 Correct 76 ms 548 KB Output is correct
78 Correct 73 ms 552 KB Output is correct
79 Correct 79 ms 576 KB Output is correct
80 Correct 75 ms 516 KB Output is correct
81 Correct 797 ms 540 KB Output is correct
82 Correct 778 ms 416 KB Output is correct
83 Correct 789 ms 412 KB Output is correct
84 Correct 769 ms 412 KB Output is correct
85 Correct 814 ms 408 KB Output is correct
86 Correct 773 ms 420 KB Output is correct
87 Correct 810 ms 416 KB Output is correct
88 Incorrect 1 ms 340 KB Output isn't correct
89 Halted 0 ms 0 KB -