답안 #583904

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

using namespace std;

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 dist = [&](int i, int j) {
        return min(abs(x[i] - x[j]), l - max(x[i], x[j]) + min(x[i], x[j]));
    };
    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 } } });
    }
    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] + dist(r, 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] + dist(l, 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] + dist(l, r)) {
            dp[l][r][c][s ^ 1] = dp[l][r][c][s] + dist(l, 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 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 448 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 452 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 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 1 ms 468 KB Output is correct
15 Correct 1 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 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 448 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 452 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 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 1 ms 468 KB Output is correct
15 Correct 1 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 588 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 852 KB Output is correct
24 Correct 2 ms 712 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 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 840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 448 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 452 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 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 1 ms 468 KB Output is correct
15 Correct 1 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 633 ms 63960 KB Output is correct
19 Correct 332 ms 38484 KB Output is correct
20 Correct 89 ms 20856 KB Output is correct
21 Correct 216 ms 36680 KB Output is correct
22 Correct 399 ms 49240 KB Output is correct
23 Correct 42 ms 17044 KB Output is correct
24 Correct 27 ms 13664 KB Output is correct
25 Correct 44 ms 16652 KB Output is correct
26 Correct 13 ms 6708 KB Output is correct
27 Correct 45 ms 17384 KB Output is correct
28 Correct 24 ms 12948 KB Output is correct
29 Correct 77 ms 17992 KB Output is correct
30 Correct 33 ms 14220 KB Output is correct
31 Correct 71 ms 16892 KB Output is correct
32 Correct 28 ms 9488 KB Output is correct
33 Correct 77 ms 16952 KB Output is correct
34 Correct 11 ms 6312 KB Output is correct
35 Correct 25 ms 16228 KB Output is correct
36 Correct 14 ms 8068 KB Output is correct
37 Correct 30 ms 17336 KB Output is correct
38 Correct 22 ms 9872 KB Output is correct
39 Correct 32 ms 17960 KB Output is correct
40 Correct 18 ms 10904 KB Output is correct
41 Correct 843 ms 82360 KB Output is correct
42 Correct 37 ms 49460 KB Output is correct
43 Correct 866 ms 82360 KB Output is correct
44 Correct 37 ms 48876 KB Output is correct
45 Correct 873 ms 82432 KB Output is correct
46 Correct 36 ms 49456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 448 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 452 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 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 1 ms 468 KB Output is correct
15 Correct 1 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 588 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 724 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 852 KB Output is correct
24 Correct 2 ms 712 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 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 840 KB Output is correct
36 Correct 633 ms 63960 KB Output is correct
37 Correct 332 ms 38484 KB Output is correct
38 Correct 89 ms 20856 KB Output is correct
39 Correct 216 ms 36680 KB Output is correct
40 Correct 399 ms 49240 KB Output is correct
41 Correct 42 ms 17044 KB Output is correct
42 Correct 27 ms 13664 KB Output is correct
43 Correct 44 ms 16652 KB Output is correct
44 Correct 13 ms 6708 KB Output is correct
45 Correct 45 ms 17384 KB Output is correct
46 Correct 24 ms 12948 KB Output is correct
47 Correct 77 ms 17992 KB Output is correct
48 Correct 33 ms 14220 KB Output is correct
49 Correct 71 ms 16892 KB Output is correct
50 Correct 28 ms 9488 KB Output is correct
51 Correct 77 ms 16952 KB Output is correct
52 Correct 11 ms 6312 KB Output is correct
53 Correct 25 ms 16228 KB Output is correct
54 Correct 14 ms 8068 KB Output is correct
55 Correct 30 ms 17336 KB Output is correct
56 Correct 22 ms 9872 KB Output is correct
57 Correct 32 ms 17960 KB Output is correct
58 Correct 18 ms 10904 KB Output is correct
59 Correct 843 ms 82360 KB Output is correct
60 Correct 37 ms 49460 KB Output is correct
61 Correct 866 ms 82360 KB Output is correct
62 Correct 37 ms 48876 KB Output is correct
63 Correct 873 ms 82432 KB Output is correct
64 Correct 36 ms 49456 KB Output is correct
65 Correct 76 ms 64196 KB Output is correct
66 Correct 76 ms 59392 KB Output is correct
67 Correct 52 ms 56204 KB Output is correct
68 Correct 53 ms 52156 KB Output is correct
69 Correct 91 ms 64412 KB Output is correct
70 Correct 153 ms 63512 KB Output is correct
71 Correct 40 ms 59552 KB Output is correct
72 Correct 118 ms 64708 KB Output is correct
73 Correct 40 ms 56856 KB Output is correct
74 Correct 130 ms 56328 KB Output is correct
75 Correct 38 ms 57804 KB Output is correct
76 Correct 555 ms 71796 KB Output is correct
77 Correct 49 ms 65996 KB Output is correct
78 Correct 327 ms 56376 KB Output is correct
79 Correct 50 ms 53696 KB Output is correct
80 Correct 536 ms 70936 KB Output is correct
81 Correct 36 ms 53196 KB Output is correct
82 Correct 330 ms 62036 KB Output is correct
83 Correct 57 ms 68656 KB Output is correct
84 Correct 323 ms 64540 KB Output is correct
85 Correct 397 ms 77240 KB Output is correct
86 Correct 409 ms 68896 KB Output is correct
87 Correct 59 ms 58728 KB Output is correct
88 Correct 170 ms 73312 KB Output is correct
89 Correct 52 ms 69828 KB Output is correct
90 Correct 46 ms 61780 KB Output is correct
91 Correct 161 ms 72824 KB Output is correct
92 Correct 71 ms 70024 KB Output is correct
93 Correct 63 ms 70064 KB Output is correct