답안 #583910

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583910 2022-06-26T13:18:30 Z pakhomovee Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
887 ms 82428 KB
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <queue>

using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const int inf = 1e9 + 1;
const int maxn = 201;
int dp[maxn][maxn][maxn][2];
bool used[maxn][maxn][maxn][2];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, l;
    cin >> n >> l;
    vector<int> x(n);
    for (int& i : x) {
        cin >> i;
    }
    vector<int> t(n);
    for (int& i : t) {
        cin >> i;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k <= n; ++k) {
                dp[i][j][k][0] = dp[i][j][k][1] = inf;
            }
        }
    }
    auto d = [&] (int i) {
        return min(x[i], l - x[i]);
    };
    priority_queue<pair<int, pair<pair<int, int>, pair<int, int>>>> q;
    if (d(0) <= t[0]) {
        dp[0][0][1][1] = d(0);
        q.push({ -dp[0][0][1][1], { { 0, 0 }, { 1 , 1 } } });
    } else {
        dp[0][0][0][1] = d(0);
        q.push({ -dp[0][0][0][1], { { 0, 0 }, { 0, 1 } } });
    }
    if (d(n - 1) <= t[n - 1]) {
        dp[n - 1][n - 1][1][0] = d(n - 1);
        q.push({ -dp[n - 1][n - 1][1][0], { { n - 1, n - 1 }, { 1, 0 } } });
    } else {
        dp[n - 1][n - 1][0][0] = d(n - 1);
        q.push({ -dp[n - 1][n - 1][0][0], { { n - 1, n - 1 }, { 0, 0 } } });
    }
    int L = l;
    while (!q.empty()) {
        auto [a, b] = q.top().second;
        auto [l, r] = a;
        auto [c, s] = b;
        q.pop();
        if (used[l][r][c][s]) continue;
        used[l][r][c][s] = 1;
        if ((r + 1) % n == l) continue;
        if (s) {
            int rp = (r + 1) % n;
            int tp = dp[l][r][c][s] + min(abs(x[r] - x[rp]), L - max(x[r], x[rp]) + min(x[r], x[rp]));
            int nc = c;
            if (tp <= t[rp]) {
                ++nc;
            }
            if (tp < dp[l][rp][nc][s]) {
                dp[l][rp][nc][s] = tp;
                q.push({ -dp[l][rp][nc][s], { { l, rp }, { nc, s } } });
            }
        } else {
            int lp = (l - 1 + n) % n;
            int tp = dp[l][r][c][s] + min(abs(x[l] - x[lp]), L - max(x[l], x[lp]) + min(x[l], x[lp]));
            int nc = c;
            if (tp <= t[lp]) {
                ++nc;
            }
            if (tp < dp[lp][r][nc][s]) {
                dp[lp][r][nc][s] = tp;
                q.push({ -dp[lp][r][nc][s], { { lp, r }, { nc, s } } });
            }
        }
        if (dp[l][r][c][s ^ 1] > dp[l][r][c][s] + min(abs(x[l] - x[r]), L - max(x[l], x[r]) + min(x[l], x[r]))) {
            dp[l][r][c][s ^ 1] = dp[l][r][c][s] + min(abs(x[l] - x[r]), L - max(x[l], x[r]) + min(x[l], x[r]));
            q.push({ -dp[l][r][c][s ^ 1], { { l, r }, { c, s ^ 1 } } });
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = 0; k <= n; ++k) {
                for (int q = 0; q < 2; ++q) {
                    if (dp[i][j][k][q] < inf) {
                        ans = max(ans, k);
                    }
                }
            }
        }
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 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 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 1 ms 852 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 852 KB Output is correct
30 Correct 1 ms 852 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 852 KB Output is correct
34 Correct 1 ms 852 KB Output is correct
35 Correct 1 ms 852 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 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 619 ms 63964 KB Output is correct
19 Correct 373 ms 38464 KB Output is correct
20 Correct 85 ms 20804 KB Output is correct
21 Correct 228 ms 36708 KB Output is correct
22 Correct 409 ms 49324 KB Output is correct
23 Correct 48 ms 17044 KB Output is correct
24 Correct 27 ms 13588 KB Output is correct
25 Correct 41 ms 16660 KB Output is correct
26 Correct 12 ms 6708 KB Output is correct
27 Correct 44 ms 17456 KB Output is correct
28 Correct 25 ms 12948 KB Output is correct
29 Correct 73 ms 17932 KB Output is correct
30 Correct 30 ms 14320 KB Output is correct
31 Correct 73 ms 16892 KB Output is correct
32 Correct 26 ms 9488 KB Output is correct
33 Correct 78 ms 17048 KB Output is correct
34 Correct 10 ms 6256 KB Output is correct
35 Correct 28 ms 16268 KB Output is correct
36 Correct 12 ms 8080 KB Output is correct
37 Correct 29 ms 17300 KB Output is correct
38 Correct 23 ms 9872 KB Output is correct
39 Correct 31 ms 18048 KB Output is correct
40 Correct 20 ms 10936 KB Output is correct
41 Correct 868 ms 82404 KB Output is correct
42 Correct 35 ms 49464 KB Output is correct
43 Correct 877 ms 82428 KB Output is correct
44 Correct 41 ms 48820 KB Output is correct
45 Correct 887 ms 82316 KB Output is correct
46 Correct 36 ms 49456 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 0 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Correct 1 ms 724 KB Output is correct
19 Correct 1 ms 596 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 0 ms 468 KB Output is correct
23 Correct 1 ms 852 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 0 ms 468 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 1 ms 852 KB Output is correct
30 Correct 1 ms 852 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 1 ms 724 KB Output is correct
33 Correct 1 ms 852 KB Output is correct
34 Correct 1 ms 852 KB Output is correct
35 Correct 1 ms 852 KB Output is correct
36 Correct 619 ms 63964 KB Output is correct
37 Correct 373 ms 38464 KB Output is correct
38 Correct 85 ms 20804 KB Output is correct
39 Correct 228 ms 36708 KB Output is correct
40 Correct 409 ms 49324 KB Output is correct
41 Correct 48 ms 17044 KB Output is correct
42 Correct 27 ms 13588 KB Output is correct
43 Correct 41 ms 16660 KB Output is correct
44 Correct 12 ms 6708 KB Output is correct
45 Correct 44 ms 17456 KB Output is correct
46 Correct 25 ms 12948 KB Output is correct
47 Correct 73 ms 17932 KB Output is correct
48 Correct 30 ms 14320 KB Output is correct
49 Correct 73 ms 16892 KB Output is correct
50 Correct 26 ms 9488 KB Output is correct
51 Correct 78 ms 17048 KB Output is correct
52 Correct 10 ms 6256 KB Output is correct
53 Correct 28 ms 16268 KB Output is correct
54 Correct 12 ms 8080 KB Output is correct
55 Correct 29 ms 17300 KB Output is correct
56 Correct 23 ms 9872 KB Output is correct
57 Correct 31 ms 18048 KB Output is correct
58 Correct 20 ms 10936 KB Output is correct
59 Correct 868 ms 82404 KB Output is correct
60 Correct 35 ms 49464 KB Output is correct
61 Correct 877 ms 82428 KB Output is correct
62 Correct 41 ms 48820 KB Output is correct
63 Correct 887 ms 82316 KB Output is correct
64 Correct 36 ms 49456 KB Output is correct
65 Correct 72 ms 64200 KB Output is correct
66 Correct 68 ms 59452 KB Output is correct
67 Correct 50 ms 56208 KB Output is correct
68 Correct 46 ms 52108 KB Output is correct
69 Correct 84 ms 64500 KB Output is correct
70 Correct 154 ms 63516 KB Output is correct
71 Correct 38 ms 59464 KB Output is correct
72 Correct 113 ms 64728 KB Output is correct
73 Correct 39 ms 56884 KB Output is correct
74 Correct 124 ms 56308 KB Output is correct
75 Correct 37 ms 57828 KB Output is correct
76 Correct 541 ms 71760 KB Output is correct
77 Correct 45 ms 65788 KB Output is correct
78 Correct 307 ms 56392 KB Output is correct
79 Correct 48 ms 53772 KB Output is correct
80 Correct 507 ms 70848 KB Output is correct
81 Correct 37 ms 53204 KB Output is correct
82 Correct 317 ms 62140 KB Output is correct
83 Correct 54 ms 68624 KB Output is correct
84 Correct 296 ms 64512 KB Output is correct
85 Correct 394 ms 77076 KB Output is correct
86 Correct 369 ms 68880 KB Output is correct
87 Correct 56 ms 58648 KB Output is correct
88 Correct 160 ms 73292 KB Output is correct
89 Correct 48 ms 69716 KB Output is correct
90 Correct 42 ms 61744 KB Output is correct
91 Correct 153 ms 72788 KB Output is correct
92 Correct 51 ms 69920 KB Output is correct
93 Correct 48 ms 70064 KB Output is correct