답안 #958147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958147 2024-04-05T02:44:34 Z peterandvoi Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
69 ms 135368 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef ngu
#include "debug.h"
#else
#define debug(...) 42
#endif

#define int long long

const int N = 205;

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

template<class A, class B>
bool mini(A &a, const B &b) {
    return a > b ? (a = b), true : false;
}

int dis(int a, int b) {
    if (x[a] > x[b]) {
        swap(a, b);
    }
    return min(x[b] - x[a], x[a] + l - x[b]);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef ngu
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
    cin >> n >> l;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> t[i];
    }
    memset(dp, 0x3f, sizeof(dp));
    const int INF = (int) 1e18;
    dp[0][0][0][0] = 0;
    int res = 0;
    for (int len = 0; len < n; ++len) {
        for (int L = 0; L <= len; ++L) {
            int R = len - L;
            for (int cnt = 0; cnt <= len; ++cnt) {
                for (int j = 0; j < 2; ++j) {
                    if (dp[L][R][cnt][j] < INF) {
                        res = max(res, cnt);
                        int T = dp[L][R][cnt][j];
                        int cur = j == 0 ? n + 1 - L : R;
                        if (T + dis(cur, n - L) <= t[n - L]) {
                            res = max(res, cnt + 1);
                            mini(dp[L + 1][R][cnt + 1][0], T + dis(cur, n - L));
                        } else {
                            mini(dp[L + 1][R][cnt][0], T + dis(cur, n - L));
                        }
                        if (T + dis(cur, R + 1) <= t[R + 1]) {
                            res = max(res, cnt + 1);
                            mini(dp[L][R + 1][cnt + 1][1], T + dis(cur, R + 1));
                        } else {
                            mini(dp[L][R + 1][cnt][1], T + dis(cur, R + 1));
                        }
                    }
                }
            }
        }
    }
    cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 135244 KB Output is correct
2 Correct 19 ms 135248 KB Output is correct
3 Correct 21 ms 135248 KB Output is correct
4 Correct 18 ms 135252 KB Output is correct
5 Correct 17 ms 135260 KB Output is correct
6 Correct 19 ms 135256 KB Output is correct
7 Correct 18 ms 135260 KB Output is correct
8 Correct 17 ms 135256 KB Output is correct
9 Correct 18 ms 135260 KB Output is correct
10 Correct 18 ms 135260 KB Output is correct
11 Correct 17 ms 135124 KB Output is correct
12 Correct 18 ms 135272 KB Output is correct
13 Correct 18 ms 135320 KB Output is correct
14 Correct 17 ms 135256 KB Output is correct
15 Correct 18 ms 135244 KB Output is correct
16 Correct 18 ms 135260 KB Output is correct
17 Correct 18 ms 135260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 135244 KB Output is correct
2 Correct 19 ms 135248 KB Output is correct
3 Correct 21 ms 135248 KB Output is correct
4 Correct 18 ms 135252 KB Output is correct
5 Correct 17 ms 135260 KB Output is correct
6 Correct 19 ms 135256 KB Output is correct
7 Correct 18 ms 135260 KB Output is correct
8 Correct 17 ms 135256 KB Output is correct
9 Correct 18 ms 135260 KB Output is correct
10 Correct 18 ms 135260 KB Output is correct
11 Correct 17 ms 135124 KB Output is correct
12 Correct 18 ms 135272 KB Output is correct
13 Correct 18 ms 135320 KB Output is correct
14 Correct 17 ms 135256 KB Output is correct
15 Correct 18 ms 135244 KB Output is correct
16 Correct 18 ms 135260 KB Output is correct
17 Correct 18 ms 135260 KB Output is correct
18 Correct 19 ms 135256 KB Output is correct
19 Correct 17 ms 135256 KB Output is correct
20 Correct 17 ms 135256 KB Output is correct
21 Correct 18 ms 135260 KB Output is correct
22 Correct 17 ms 135256 KB Output is correct
23 Correct 18 ms 135124 KB Output is correct
24 Correct 18 ms 135256 KB Output is correct
25 Correct 18 ms 135260 KB Output is correct
26 Correct 18 ms 135260 KB Output is correct
27 Correct 20 ms 135100 KB Output is correct
28 Correct 17 ms 135260 KB Output is correct
29 Correct 18 ms 135224 KB Output is correct
30 Correct 18 ms 135260 KB Output is correct
31 Correct 18 ms 135260 KB Output is correct
32 Correct 18 ms 135368 KB Output is correct
33 Correct 18 ms 135328 KB Output is correct
34 Correct 17 ms 135256 KB Output is correct
35 Correct 18 ms 135256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 135244 KB Output is correct
2 Correct 19 ms 135248 KB Output is correct
3 Correct 21 ms 135248 KB Output is correct
4 Correct 18 ms 135252 KB Output is correct
5 Correct 17 ms 135260 KB Output is correct
6 Correct 19 ms 135256 KB Output is correct
7 Correct 18 ms 135260 KB Output is correct
8 Correct 17 ms 135256 KB Output is correct
9 Correct 18 ms 135260 KB Output is correct
10 Correct 18 ms 135260 KB Output is correct
11 Correct 17 ms 135124 KB Output is correct
12 Correct 18 ms 135272 KB Output is correct
13 Correct 18 ms 135320 KB Output is correct
14 Correct 17 ms 135256 KB Output is correct
15 Correct 18 ms 135244 KB Output is correct
16 Correct 18 ms 135260 KB Output is correct
17 Correct 18 ms 135260 KB Output is correct
18 Correct 37 ms 135260 KB Output is correct
19 Correct 31 ms 135256 KB Output is correct
20 Correct 22 ms 135256 KB Output is correct
21 Correct 27 ms 135260 KB Output is correct
22 Correct 31 ms 135308 KB Output is correct
23 Correct 22 ms 135260 KB Output is correct
24 Correct 19 ms 135256 KB Output is correct
25 Correct 21 ms 135260 KB Output is correct
26 Correct 21 ms 135260 KB Output is correct
27 Correct 22 ms 135268 KB Output is correct
28 Correct 19 ms 135260 KB Output is correct
29 Correct 21 ms 135308 KB Output is correct
30 Correct 20 ms 135332 KB Output is correct
31 Correct 23 ms 135256 KB Output is correct
32 Correct 20 ms 135248 KB Output is correct
33 Correct 22 ms 135256 KB Output is correct
34 Correct 19 ms 135092 KB Output is correct
35 Correct 20 ms 135256 KB Output is correct
36 Correct 19 ms 135260 KB Output is correct
37 Correct 20 ms 135256 KB Output is correct
38 Correct 22 ms 135260 KB Output is correct
39 Correct 20 ms 135260 KB Output is correct
40 Correct 19 ms 135252 KB Output is correct
41 Correct 44 ms 135256 KB Output is correct
42 Correct 25 ms 135096 KB Output is correct
43 Correct 45 ms 135308 KB Output is correct
44 Correct 25 ms 135268 KB Output is correct
45 Correct 46 ms 135260 KB Output is correct
46 Correct 25 ms 135252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 135244 KB Output is correct
2 Correct 19 ms 135248 KB Output is correct
3 Correct 21 ms 135248 KB Output is correct
4 Correct 18 ms 135252 KB Output is correct
5 Correct 17 ms 135260 KB Output is correct
6 Correct 19 ms 135256 KB Output is correct
7 Correct 18 ms 135260 KB Output is correct
8 Correct 17 ms 135256 KB Output is correct
9 Correct 18 ms 135260 KB Output is correct
10 Correct 18 ms 135260 KB Output is correct
11 Correct 17 ms 135124 KB Output is correct
12 Correct 18 ms 135272 KB Output is correct
13 Correct 18 ms 135320 KB Output is correct
14 Correct 17 ms 135256 KB Output is correct
15 Correct 18 ms 135244 KB Output is correct
16 Correct 18 ms 135260 KB Output is correct
17 Correct 18 ms 135260 KB Output is correct
18 Correct 19 ms 135256 KB Output is correct
19 Correct 17 ms 135256 KB Output is correct
20 Correct 17 ms 135256 KB Output is correct
21 Correct 18 ms 135260 KB Output is correct
22 Correct 17 ms 135256 KB Output is correct
23 Correct 18 ms 135124 KB Output is correct
24 Correct 18 ms 135256 KB Output is correct
25 Correct 18 ms 135260 KB Output is correct
26 Correct 18 ms 135260 KB Output is correct
27 Correct 20 ms 135100 KB Output is correct
28 Correct 17 ms 135260 KB Output is correct
29 Correct 18 ms 135224 KB Output is correct
30 Correct 18 ms 135260 KB Output is correct
31 Correct 18 ms 135260 KB Output is correct
32 Correct 18 ms 135368 KB Output is correct
33 Correct 18 ms 135328 KB Output is correct
34 Correct 17 ms 135256 KB Output is correct
35 Correct 18 ms 135256 KB Output is correct
36 Correct 37 ms 135260 KB Output is correct
37 Correct 31 ms 135256 KB Output is correct
38 Correct 22 ms 135256 KB Output is correct
39 Correct 27 ms 135260 KB Output is correct
40 Correct 31 ms 135308 KB Output is correct
41 Correct 22 ms 135260 KB Output is correct
42 Correct 19 ms 135256 KB Output is correct
43 Correct 21 ms 135260 KB Output is correct
44 Correct 21 ms 135260 KB Output is correct
45 Correct 22 ms 135268 KB Output is correct
46 Correct 19 ms 135260 KB Output is correct
47 Correct 21 ms 135308 KB Output is correct
48 Correct 20 ms 135332 KB Output is correct
49 Correct 23 ms 135256 KB Output is correct
50 Correct 20 ms 135248 KB Output is correct
51 Correct 22 ms 135256 KB Output is correct
52 Correct 19 ms 135092 KB Output is correct
53 Correct 20 ms 135256 KB Output is correct
54 Correct 19 ms 135260 KB Output is correct
55 Correct 20 ms 135256 KB Output is correct
56 Correct 22 ms 135260 KB Output is correct
57 Correct 20 ms 135260 KB Output is correct
58 Correct 19 ms 135252 KB Output is correct
59 Correct 44 ms 135256 KB Output is correct
60 Correct 25 ms 135096 KB Output is correct
61 Correct 45 ms 135308 KB Output is correct
62 Correct 25 ms 135268 KB Output is correct
63 Correct 46 ms 135260 KB Output is correct
64 Correct 25 ms 135252 KB Output is correct
65 Correct 41 ms 135316 KB Output is correct
66 Correct 39 ms 135260 KB Output is correct
67 Correct 45 ms 135316 KB Output is correct
68 Correct 34 ms 135260 KB Output is correct
69 Correct 46 ms 135252 KB Output is correct
70 Correct 42 ms 135256 KB Output is correct
71 Correct 36 ms 135260 KB Output is correct
72 Correct 41 ms 135256 KB Output is correct
73 Correct 32 ms 135248 KB Output is correct
74 Correct 35 ms 135260 KB Output is correct
75 Correct 35 ms 135260 KB Output is correct
76 Correct 49 ms 135260 KB Output is correct
77 Correct 41 ms 135248 KB Output is correct
78 Correct 44 ms 135256 KB Output is correct
79 Correct 36 ms 135256 KB Output is correct
80 Correct 48 ms 135260 KB Output is correct
81 Correct 34 ms 135260 KB Output is correct
82 Correct 32 ms 135260 KB Output is correct
83 Correct 42 ms 135316 KB Output is correct
84 Correct 33 ms 135260 KB Output is correct
85 Correct 35 ms 135256 KB Output is correct
86 Correct 35 ms 135260 KB Output is correct
87 Correct 38 ms 135252 KB Output is correct
88 Correct 54 ms 135256 KB Output is correct
89 Correct 45 ms 135260 KB Output is correct
90 Correct 26 ms 135256 KB Output is correct
91 Correct 53 ms 135256 KB Output is correct
92 Correct 46 ms 135312 KB Output is correct
93 Correct 29 ms 135324 KB Output is correct