답안 #593703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593703 2022-07-11T13:52:04 Z piOOE Let's Win the Election (JOI22_ho_t3) C++17
61 / 100
2500 ms 984644 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using db = double;

const int N = 501;

db dp[N][N][N]; //id, b, a

db solved[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, K;
    cin >> n >> K;
    vector<int> a(n), b(n), ob(n);
    int cntb = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        if (b[i] != -1) {
            cntb += 1;
        }
    }
    iota(ob.begin(), ob.end(), 0);
    sort(ob.begin(), ob.end(), [&](int i, int j) {
        if (b[i] == -1) return false;
        if (b[j] == -1) return true;
        return b[i] < b[j];
    });
    const db inf = 1e12;
    auto solve = [&](int mx) -> db {
        if (solved[mx] == 0) {
            for (int i = 0; i <= n; ++i) {
                for (int j = 0; j <= mx; ++j) {
                    for (int k = 0; k <= K - j; ++k) {
                        dp[i][j][k] = inf;
                    }
                }
            }
            dp[0][0][0] = 0;
            for (int i = 1; i <= n; ++i) {
                //don't take
                for (int j = 0; j <= min(i, mx); ++j) {
                    for (int k = 0; k <= min(i, K) - j; ++k) {
                        dp[i][j][k] = dp[i - 1][j][k];
                    }
                }
                //take a
                int idx = ob[i - 1];
                for (int j = 0; j <= min(i, mx); ++j) {
                    for (int k = 1; k <= min(i, K) - j; ++k) {
                        dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j][k - 1] + a[idx] / db(mx + 1));
                    }
                }
                if (b[idx] != -1) {
                    for (int j = 1; j <= min(i, mx); ++j) {
                        for (int k = 0; k <= min(i, K) - j; ++k) {
                            dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j - 1][k] + b[idx] / db(j));
                        }
                    }
                }
            }
            solved[mx] = dp[n][mx][K - mx];
        }
        return solved[mx];
    };
    int r = min(K, cntb);
    int x = 0;
    for (int k = 9; k > -1; --k) {
        db ansL = (x >= (1 << k) ? solve(x - (1 << k)) : inf);
        db ans = solve(x);
        db ansR = (x + (1 << k) <= r ? solve(x + (1 << k)) : inf);
        if (ansL <= ans && ansL <= ansR) {
            x -= (1 << k);
        } else if (ansR <= ans) {
            x += (1 << k);
        }
    }
    cout << fixed << setprecision(20) << solve(x);
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 4428 KB Output is correct
6 Correct 3 ms 4692 KB Output is correct
7 Correct 3 ms 5204 KB Output is correct
8 Correct 3 ms 5712 KB Output is correct
9 Correct 3 ms 6100 KB Output is correct
10 Correct 3 ms 5588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 4428 KB Output is correct
6 Correct 3 ms 4692 KB Output is correct
7 Correct 3 ms 5204 KB Output is correct
8 Correct 3 ms 5712 KB Output is correct
9 Correct 3 ms 6100 KB Output is correct
10 Correct 3 ms 5588 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 520 ms 298280 KB Output is correct
13 Correct 477 ms 255324 KB Output is correct
14 Correct 285 ms 192580 KB Output is correct
15 Correct 1984 ms 690536 KB Output is correct
16 Correct 1531 ms 506644 KB Output is correct
17 Correct 450 ms 193480 KB Output is correct
18 Execution timed out 2569 ms 984644 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 1364 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 2 ms 1488 KB Output is correct
23 Correct 2 ms 1364 KB Output is correct
24 Correct 1 ms 1364 KB Output is correct
25 Correct 2 ms 1748 KB Output is correct
26 Correct 1 ms 1748 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1364 KB Output is correct
29 Correct 1 ms 1364 KB Output is correct
30 Correct 1 ms 1608 KB Output is correct
31 Correct 1 ms 1364 KB Output is correct
32 Correct 1 ms 1620 KB Output is correct
33 Correct 1 ms 1364 KB Output is correct
34 Correct 1 ms 1484 KB Output is correct
35 Correct 1 ms 1364 KB Output is correct
36 Correct 1 ms 1364 KB Output is correct
37 Correct 1 ms 1620 KB Output is correct
38 Correct 1 ms 1364 KB Output is correct
39 Correct 1 ms 1612 KB Output is correct
40 Correct 1 ms 1484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1364 KB Output is correct
20 Correct 1 ms 1364 KB Output is correct
21 Correct 1 ms 1364 KB Output is correct
22 Correct 2 ms 1488 KB Output is correct
23 Correct 2 ms 1364 KB Output is correct
24 Correct 1 ms 1364 KB Output is correct
25 Correct 2 ms 1748 KB Output is correct
26 Correct 1 ms 1748 KB Output is correct
27 Correct 1 ms 1108 KB Output is correct
28 Correct 1 ms 1364 KB Output is correct
29 Correct 1 ms 1364 KB Output is correct
30 Correct 1 ms 1608 KB Output is correct
31 Correct 1 ms 1364 KB Output is correct
32 Correct 1 ms 1620 KB Output is correct
33 Correct 1 ms 1364 KB Output is correct
34 Correct 1 ms 1484 KB Output is correct
35 Correct 1 ms 1364 KB Output is correct
36 Correct 1 ms 1364 KB Output is correct
37 Correct 1 ms 1620 KB Output is correct
38 Correct 1 ms 1364 KB Output is correct
39 Correct 1 ms 1612 KB Output is correct
40 Correct 1 ms 1484 KB Output is correct
41 Correct 2 ms 5844 KB Output is correct
42 Correct 4 ms 6740 KB Output is correct
43 Correct 6 ms 10580 KB Output is correct
44 Correct 8 ms 12116 KB Output is correct
45 Correct 14 ms 20052 KB Output is correct
46 Correct 13 ms 20096 KB Output is correct
47 Correct 17 ms 26324 KB Output is correct
48 Correct 24 ms 26372 KB Output is correct
49 Correct 28 ms 32740 KB Output is correct
50 Correct 20 ms 26324 KB Output is correct
51 Correct 40 ms 39052 KB Output is correct
52 Correct 32 ms 32732 KB Output is correct
53 Correct 20 ms 26428 KB Output is correct
54 Correct 21 ms 26420 KB Output is correct
55 Correct 22 ms 26316 KB Output is correct
56 Correct 16 ms 26324 KB Output is correct
57 Correct 20 ms 26316 KB Output is correct
58 Correct 20 ms 26324 KB Output is correct
59 Correct 22 ms 26324 KB Output is correct
60 Correct 20 ms 26296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2613 ms 757656 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 4428 KB Output is correct
6 Correct 3 ms 4692 KB Output is correct
7 Correct 3 ms 5204 KB Output is correct
8 Correct 3 ms 5712 KB Output is correct
9 Correct 3 ms 6100 KB Output is correct
10 Correct 3 ms 5588 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 520 ms 298280 KB Output is correct
13 Correct 477 ms 255324 KB Output is correct
14 Correct 285 ms 192580 KB Output is correct
15 Correct 1984 ms 690536 KB Output is correct
16 Correct 1531 ms 506644 KB Output is correct
17 Correct 450 ms 193480 KB Output is correct
18 Execution timed out 2569 ms 984644 KB Time limit exceeded
19 Halted 0 ms 0 KB -