#include <bits/stdc++.h>
using namespace std;
int N, L, X[205], T[205], D[205][205][205][2], ans;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> L;
for (int i = 1; i <= N; ++i) cin >> X[i];
for (int i = 1; i <= N; ++i) cin >> T[i];
for (int i = 0; i <= N; ++i)
for (int j = 1; j <= N + 1; ++j)
for (int k = 0; k <= N; ++k)
D[i][j][k][0] = D[i][j][k][1] = 1e9;
X[N + 1] = L;
D[0][N + 1][0][0] = D[0][N + 1][0][1] = 0;
for (int i = 0; i <= N; ++i) {
for (int j = N + 1; j > i; --j) {
for (int k = 0; k <= N; ++k) {
if (D[i][j][k][0] != 1e9 || D[i][j][k][1] != 1e9) ans = max(ans, k);
if (D[i][j][k][0] + X[i + 1] - X[i] <= T[i + 1]) D[i + 1][j][k + 1][0] = min(D[i + 1][j][k + 1][0], D[i][j][k][0] + X[i + 1] - X[i]);
else D[i + 1][j][k][0] = min(D[i + 1][j][k][0], D[i][j][k][0] + X[i + 1] - X[i]);
if (D[i][j][k][0] + X[i] + L - X[j - 1] <= T[j - 1]) D[i][j - 1][k + 1][1] = min(D[i][j - 1][k + 1][1], D[i][j][k][0] + X[i] + L - X[j - 1]);
else D[i][j - 1][k][1] = min(D[i][j - 1][k][1], D[i][j][k][0] + X[i] + L - X[j - 1]);
if (D[i][j][k][1] + X[j] - X[j - 1] <= T[j - 1]) D[i][j - 1][k + 1][1] = min(D[i][j - 1][k + 1][1], D[i][j][k][1] + X[j] - X[j - 1]);
else D[i][j - 1][k][1] = min(D[i][j - 1][k][1], D[i][j][k][1] + X[j] - X[j - 1]);
if (D[i][j][k][1] + L - X[j] + X[i + 1] <= T[i + 1]) D[i + 1][j][k + 1][0] = min(D[i + 1][j][k + 1][0], D[i][j][k][1] + L - X[j] + X[i + 1]);
else D[i + 1][j][k][0] = min(D[i + 1][j][k][0], D[i][j][k][1] + L - X[j] + X[i + 1]);
}
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
4 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
4 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
21 |
Correct |
5 ms |
768 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
768 KB |
Output is correct |
24 |
Correct |
5 ms |
640 KB |
Output is correct |
25 |
Correct |
5 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
768 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
768 KB |
Output is correct |
30 |
Correct |
5 ms |
768 KB |
Output is correct |
31 |
Correct |
5 ms |
768 KB |
Output is correct |
32 |
Correct |
5 ms |
768 KB |
Output is correct |
33 |
Correct |
5 ms |
768 KB |
Output is correct |
34 |
Correct |
5 ms |
768 KB |
Output is correct |
35 |
Correct |
6 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
4 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
52 ms |
52992 KB |
Output is correct |
19 |
Correct |
30 ms |
32384 KB |
Output is correct |
20 |
Correct |
17 ms |
17408 KB |
Output is correct |
21 |
Correct |
30 ms |
30572 KB |
Output is correct |
22 |
Correct |
37 ms |
39424 KB |
Output is correct |
23 |
Correct |
16 ms |
14848 KB |
Output is correct |
24 |
Correct |
12 ms |
11648 KB |
Output is correct |
25 |
Correct |
16 ms |
14592 KB |
Output is correct |
26 |
Correct |
8 ms |
5760 KB |
Output is correct |
27 |
Correct |
15 ms |
15104 KB |
Output is correct |
28 |
Correct |
12 ms |
10880 KB |
Output is correct |
29 |
Correct |
15 ms |
15488 KB |
Output is correct |
30 |
Correct |
14 ms |
12288 KB |
Output is correct |
31 |
Correct |
14 ms |
14592 KB |
Output is correct |
32 |
Correct |
9 ms |
7808 KB |
Output is correct |
33 |
Correct |
16 ms |
14592 KB |
Output is correct |
34 |
Correct |
7 ms |
5376 KB |
Output is correct |
35 |
Correct |
13 ms |
14208 KB |
Output is correct |
36 |
Correct |
8 ms |
6912 KB |
Output is correct |
37 |
Correct |
15 ms |
15104 KB |
Output is correct |
38 |
Correct |
11 ms |
8448 KB |
Output is correct |
39 |
Correct |
15 ms |
15744 KB |
Output is correct |
40 |
Correct |
11 ms |
9472 KB |
Output is correct |
41 |
Correct |
63 ms |
65280 KB |
Output is correct |
42 |
Correct |
41 ms |
44160 KB |
Output is correct |
43 |
Correct |
65 ms |
65280 KB |
Output is correct |
44 |
Correct |
40 ms |
43648 KB |
Output is correct |
45 |
Correct |
66 ms |
65272 KB |
Output is correct |
46 |
Correct |
46 ms |
44160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
4 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
21 |
Correct |
5 ms |
768 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
768 KB |
Output is correct |
24 |
Correct |
5 ms |
640 KB |
Output is correct |
25 |
Correct |
5 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
768 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
768 KB |
Output is correct |
30 |
Correct |
5 ms |
768 KB |
Output is correct |
31 |
Correct |
5 ms |
768 KB |
Output is correct |
32 |
Correct |
5 ms |
768 KB |
Output is correct |
33 |
Correct |
5 ms |
768 KB |
Output is correct |
34 |
Correct |
5 ms |
768 KB |
Output is correct |
35 |
Correct |
6 ms |
768 KB |
Output is correct |
36 |
Correct |
52 ms |
52992 KB |
Output is correct |
37 |
Correct |
30 ms |
32384 KB |
Output is correct |
38 |
Correct |
17 ms |
17408 KB |
Output is correct |
39 |
Correct |
30 ms |
30572 KB |
Output is correct |
40 |
Correct |
37 ms |
39424 KB |
Output is correct |
41 |
Correct |
16 ms |
14848 KB |
Output is correct |
42 |
Correct |
12 ms |
11648 KB |
Output is correct |
43 |
Correct |
16 ms |
14592 KB |
Output is correct |
44 |
Correct |
8 ms |
5760 KB |
Output is correct |
45 |
Correct |
15 ms |
15104 KB |
Output is correct |
46 |
Correct |
12 ms |
10880 KB |
Output is correct |
47 |
Correct |
15 ms |
15488 KB |
Output is correct |
48 |
Correct |
14 ms |
12288 KB |
Output is correct |
49 |
Correct |
14 ms |
14592 KB |
Output is correct |
50 |
Correct |
9 ms |
7808 KB |
Output is correct |
51 |
Correct |
16 ms |
14592 KB |
Output is correct |
52 |
Correct |
7 ms |
5376 KB |
Output is correct |
53 |
Correct |
13 ms |
14208 KB |
Output is correct |
54 |
Correct |
8 ms |
6912 KB |
Output is correct |
55 |
Correct |
15 ms |
15104 KB |
Output is correct |
56 |
Correct |
11 ms |
8448 KB |
Output is correct |
57 |
Correct |
15 ms |
15744 KB |
Output is correct |
58 |
Correct |
11 ms |
9472 KB |
Output is correct |
59 |
Correct |
63 ms |
65280 KB |
Output is correct |
60 |
Correct |
41 ms |
44160 KB |
Output is correct |
61 |
Correct |
65 ms |
65280 KB |
Output is correct |
62 |
Correct |
40 ms |
43648 KB |
Output is correct |
63 |
Correct |
66 ms |
65272 KB |
Output is correct |
64 |
Correct |
46 ms |
44160 KB |
Output is correct |
65 |
Correct |
58 ms |
59008 KB |
Output is correct |
66 |
Correct |
60 ms |
54264 KB |
Output is correct |
67 |
Correct |
49 ms |
51968 KB |
Output is correct |
68 |
Correct |
46 ms |
48000 KB |
Output is correct |
69 |
Correct |
58 ms |
58488 KB |
Output is correct |
70 |
Correct |
53 ms |
56056 KB |
Output is correct |
71 |
Correct |
58 ms |
56568 KB |
Output is correct |
72 |
Correct |
56 ms |
57208 KB |
Output is correct |
73 |
Correct |
51 ms |
52984 KB |
Output is correct |
74 |
Correct |
47 ms |
49656 KB |
Output is correct |
75 |
Correct |
57 ms |
54784 KB |
Output is correct |
76 |
Correct |
70 ms |
62848 KB |
Output is correct |
77 |
Correct |
63 ms |
62712 KB |
Output is correct |
78 |
Correct |
49 ms |
48512 KB |
Output is correct |
79 |
Correct |
52 ms |
50168 KB |
Output is correct |
80 |
Correct |
67 ms |
61568 KB |
Output is correct |
81 |
Correct |
47 ms |
50816 KB |
Output is correct |
82 |
Correct |
54 ms |
53632 KB |
Output is correct |
83 |
Correct |
72 ms |
65272 KB |
Output is correct |
84 |
Correct |
52 ms |
55936 KB |
Output is correct |
85 |
Correct |
66 ms |
60920 KB |
Output is correct |
86 |
Correct |
57 ms |
59640 KB |
Output is correct |
87 |
Correct |
62 ms |
54776 KB |
Output is correct |
88 |
Correct |
72 ms |
65912 KB |
Output is correct |
89 |
Correct |
74 ms |
65912 KB |
Output is correct |
90 |
Correct |
59 ms |
55416 KB |
Output is correct |
91 |
Correct |
68 ms |
65912 KB |
Output is correct |
92 |
Correct |
67 ms |
66040 KB |
Output is correct |
93 |
Correct |
62 ms |
64632 KB |
Output is correct |