답안 #630031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
630031 2022-08-15T14:41:21 Z colossal_pepe Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
1025 ms 42308 KB
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

const int INF = (int)1e9 + 1;
const int N = 205;

int n, l, x[N], t[N], dp[N][N][N];

int dist(int x1, int x2) {
    if (x1 > x2) swap(x1, x2);
    return min(x2 - x1, l - x2 + x1);
}

int solve() {
    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] = -INF;
            }
        }
    }
    int ans = 0;
    priority_queue<tuple<int, int, int, int>> pq;
    dp[0][n + 1][0] = 0;
    pq.push({0, 0, n + 1, 0});
    while (not pq.empty()) {
        int d, i, j, c;
        tie(d, i, j, c) = pq.top();
        ans = max(ans, c);
        pq.pop();
        if (dp[i][j][c] != d or abs(i - j) == 1) continue;
        int cur = i, l = min(i, j), r = max(i, j);
        {
            // cur -> l + 1
            int d_nxt = min(INF, dist(x[cur], x[l + 1]) - d);
            int c_nxt = (d_nxt <= t[l + 1]) + c;
            if (dp[l + 1][r][c_nxt] < -d_nxt) {
                dp[l + 1][r][c_nxt] = -d_nxt;
                pq.push({-d_nxt, l + 1, r, c_nxt});
            }
        }
        {
            // cur -> r - 1
            int d_nxt = min(INF, dist(x[cur], x[r - 1]) - d);
            int c_nxt = (d_nxt <= t[r - 1]) + c;
            if (dp[r - 1][l][c_nxt] < -d_nxt) {
                dp[r - 1][l][c_nxt] = -d_nxt;
                pq.push({-d_nxt, r - 1, l, c_nxt});
            }
        }
    }
    return ans;
}

int main() {
    cin >> n >> l;
    x[0] = 0;
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
    }
    cout << solve() << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 34004 KB Output is correct
2 Correct 17 ms 33904 KB Output is correct
3 Correct 16 ms 34084 KB Output is correct
4 Correct 16 ms 34000 KB Output is correct
5 Correct 16 ms 34004 KB Output is correct
6 Correct 20 ms 33996 KB Output is correct
7 Correct 16 ms 33924 KB Output is correct
8 Correct 17 ms 34004 KB Output is correct
9 Correct 17 ms 34004 KB Output is correct
10 Correct 16 ms 33956 KB Output is correct
11 Correct 18 ms 34004 KB Output is correct
12 Correct 17 ms 33984 KB Output is correct
13 Correct 18 ms 33992 KB Output is correct
14 Correct 16 ms 34004 KB Output is correct
15 Correct 16 ms 33896 KB Output is correct
16 Correct 16 ms 34004 KB Output is correct
17 Correct 16 ms 34004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 34004 KB Output is correct
2 Correct 17 ms 33904 KB Output is correct
3 Correct 16 ms 34084 KB Output is correct
4 Correct 16 ms 34000 KB Output is correct
5 Correct 16 ms 34004 KB Output is correct
6 Correct 20 ms 33996 KB Output is correct
7 Correct 16 ms 33924 KB Output is correct
8 Correct 17 ms 34004 KB Output is correct
9 Correct 17 ms 34004 KB Output is correct
10 Correct 16 ms 33956 KB Output is correct
11 Correct 18 ms 34004 KB Output is correct
12 Correct 17 ms 33984 KB Output is correct
13 Correct 18 ms 33992 KB Output is correct
14 Correct 16 ms 34004 KB Output is correct
15 Correct 16 ms 33896 KB Output is correct
16 Correct 16 ms 34004 KB Output is correct
17 Correct 16 ms 34004 KB Output is correct
18 Correct 16 ms 33948 KB Output is correct
19 Correct 16 ms 34016 KB Output is correct
20 Correct 16 ms 34004 KB Output is correct
21 Correct 16 ms 34004 KB Output is correct
22 Correct 19 ms 33940 KB Output is correct
23 Correct 17 ms 34004 KB Output is correct
24 Correct 16 ms 34004 KB Output is correct
25 Correct 17 ms 33936 KB Output is correct
26 Correct 20 ms 33968 KB Output is correct
27 Correct 18 ms 34004 KB Output is correct
28 Correct 17 ms 34004 KB Output is correct
29 Correct 17 ms 34004 KB Output is correct
30 Correct 17 ms 33940 KB Output is correct
31 Correct 17 ms 34004 KB Output is correct
32 Correct 16 ms 33908 KB Output is correct
33 Correct 16 ms 34004 KB Output is correct
34 Correct 18 ms 34008 KB Output is correct
35 Correct 17 ms 34032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 34004 KB Output is correct
2 Correct 17 ms 33904 KB Output is correct
3 Correct 16 ms 34084 KB Output is correct
4 Correct 16 ms 34000 KB Output is correct
5 Correct 16 ms 34004 KB Output is correct
6 Correct 20 ms 33996 KB Output is correct
7 Correct 16 ms 33924 KB Output is correct
8 Correct 17 ms 34004 KB Output is correct
9 Correct 17 ms 34004 KB Output is correct
10 Correct 16 ms 33956 KB Output is correct
11 Correct 18 ms 34004 KB Output is correct
12 Correct 17 ms 33984 KB Output is correct
13 Correct 18 ms 33992 KB Output is correct
14 Correct 16 ms 34004 KB Output is correct
15 Correct 16 ms 33896 KB Output is correct
16 Correct 16 ms 34004 KB Output is correct
17 Correct 16 ms 34004 KB Output is correct
18 Correct 598 ms 38144 KB Output is correct
19 Correct 285 ms 36156 KB Output is correct
20 Correct 93 ms 35128 KB Output is correct
21 Correct 223 ms 36172 KB Output is correct
22 Correct 450 ms 38176 KB Output is correct
23 Correct 111 ms 35164 KB Output is correct
24 Correct 36 ms 34636 KB Output is correct
25 Correct 97 ms 35120 KB Output is correct
26 Correct 26 ms 34180 KB Output is correct
27 Correct 111 ms 35128 KB Output is correct
28 Correct 36 ms 34372 KB Output is correct
29 Correct 92 ms 34596 KB Output is correct
30 Correct 36 ms 34640 KB Output is correct
31 Correct 86 ms 34572 KB Output is correct
32 Correct 36 ms 34648 KB Output is correct
33 Correct 83 ms 34608 KB Output is correct
34 Correct 26 ms 34152 KB Output is correct
35 Correct 31 ms 34388 KB Output is correct
36 Correct 25 ms 34376 KB Output is correct
37 Correct 39 ms 34368 KB Output is correct
38 Correct 47 ms 34628 KB Output is correct
39 Correct 37 ms 34388 KB Output is correct
40 Correct 29 ms 34336 KB Output is correct
41 Correct 1018 ms 42284 KB Output is correct
42 Correct 28 ms 34344 KB Output is correct
43 Correct 997 ms 42296 KB Output is correct
44 Correct 25 ms 34140 KB Output is correct
45 Correct 1025 ms 42308 KB Output is correct
46 Correct 22 ms 34232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 34004 KB Output is correct
2 Correct 17 ms 33904 KB Output is correct
3 Correct 16 ms 34084 KB Output is correct
4 Correct 16 ms 34000 KB Output is correct
5 Correct 16 ms 34004 KB Output is correct
6 Correct 20 ms 33996 KB Output is correct
7 Correct 16 ms 33924 KB Output is correct
8 Correct 17 ms 34004 KB Output is correct
9 Correct 17 ms 34004 KB Output is correct
10 Correct 16 ms 33956 KB Output is correct
11 Correct 18 ms 34004 KB Output is correct
12 Correct 17 ms 33984 KB Output is correct
13 Correct 18 ms 33992 KB Output is correct
14 Correct 16 ms 34004 KB Output is correct
15 Correct 16 ms 33896 KB Output is correct
16 Correct 16 ms 34004 KB Output is correct
17 Correct 16 ms 34004 KB Output is correct
18 Correct 16 ms 33948 KB Output is correct
19 Correct 16 ms 34016 KB Output is correct
20 Correct 16 ms 34004 KB Output is correct
21 Correct 16 ms 34004 KB Output is correct
22 Correct 19 ms 33940 KB Output is correct
23 Correct 17 ms 34004 KB Output is correct
24 Correct 16 ms 34004 KB Output is correct
25 Correct 17 ms 33936 KB Output is correct
26 Correct 20 ms 33968 KB Output is correct
27 Correct 18 ms 34004 KB Output is correct
28 Correct 17 ms 34004 KB Output is correct
29 Correct 17 ms 34004 KB Output is correct
30 Correct 17 ms 33940 KB Output is correct
31 Correct 17 ms 34004 KB Output is correct
32 Correct 16 ms 33908 KB Output is correct
33 Correct 16 ms 34004 KB Output is correct
34 Correct 18 ms 34008 KB Output is correct
35 Correct 17 ms 34032 KB Output is correct
36 Correct 598 ms 38144 KB Output is correct
37 Correct 285 ms 36156 KB Output is correct
38 Correct 93 ms 35128 KB Output is correct
39 Correct 223 ms 36172 KB Output is correct
40 Correct 450 ms 38176 KB Output is correct
41 Correct 111 ms 35164 KB Output is correct
42 Correct 36 ms 34636 KB Output is correct
43 Correct 97 ms 35120 KB Output is correct
44 Correct 26 ms 34180 KB Output is correct
45 Correct 111 ms 35128 KB Output is correct
46 Correct 36 ms 34372 KB Output is correct
47 Correct 92 ms 34596 KB Output is correct
48 Correct 36 ms 34640 KB Output is correct
49 Correct 86 ms 34572 KB Output is correct
50 Correct 36 ms 34648 KB Output is correct
51 Correct 83 ms 34608 KB Output is correct
52 Correct 26 ms 34152 KB Output is correct
53 Correct 31 ms 34388 KB Output is correct
54 Correct 25 ms 34376 KB Output is correct
55 Correct 39 ms 34368 KB Output is correct
56 Correct 47 ms 34628 KB Output is correct
57 Correct 37 ms 34388 KB Output is correct
58 Correct 29 ms 34336 KB Output is correct
59 Correct 1018 ms 42284 KB Output is correct
60 Correct 28 ms 34344 KB Output is correct
61 Correct 997 ms 42296 KB Output is correct
62 Correct 25 ms 34140 KB Output is correct
63 Correct 1025 ms 42308 KB Output is correct
64 Correct 22 ms 34232 KB Output is correct
65 Correct 58 ms 34588 KB Output is correct
66 Correct 55 ms 34572 KB Output is correct
67 Correct 47 ms 34388 KB Output is correct
68 Correct 41 ms 34504 KB Output is correct
69 Correct 64 ms 34612 KB Output is correct
70 Correct 152 ms 36120 KB Output is correct
71 Correct 31 ms 34388 KB Output is correct
72 Correct 181 ms 35136 KB Output is correct
73 Correct 116 ms 35140 KB Output is correct
74 Correct 141 ms 35116 KB Output is correct
75 Correct 26 ms 34076 KB Output is correct
76 Correct 760 ms 38240 KB Output is correct
77 Correct 33 ms 34224 KB Output is correct
78 Correct 490 ms 36136 KB Output is correct
79 Correct 41 ms 34380 KB Output is correct
80 Correct 734 ms 38192 KB Output is correct
81 Correct 30 ms 34248 KB Output is correct
82 Correct 287 ms 38260 KB Output is correct
83 Correct 32 ms 34176 KB Output is correct
84 Correct 337 ms 38196 KB Output is correct
85 Correct 342 ms 38240 KB Output is correct
86 Correct 412 ms 38256 KB Output is correct
87 Correct 35 ms 34388 KB Output is correct
88 Correct 191 ms 36124 KB Output is correct
89 Correct 27 ms 34148 KB Output is correct
90 Correct 28 ms 34336 KB Output is correct
91 Correct 168 ms 35140 KB Output is correct
92 Correct 32 ms 34192 KB Output is correct
93 Correct 23 ms 34132 KB Output is correct