#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 205;
const long long llINF = 1e18 + 7;
int X[MAX_N], T[MAX_N];
long long dp1[MAX_N][MAX_N][MAX_N], dp2[MAX_N][MAX_N][MAX_N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, L;
cin >> N >> L;
for(int i = 1; i <= N; i++) {
cin >> X[i];
}
for(int i = 1; i <= N; i++) {
cin >> T[i];
}
X[N + 1] = L;
for(int k = 0; k <= N; k++) {
for(int i = 0; i <= N + 1; i++) {
for(int j = 0; j <= N + 1; j++) {
dp1[i][j][k] = llINF;
dp2[i][j][k] = llINF;
}
}
}
int ans = 0;
dp1[0][N + 1][0] = dp2[0][N + 1][0] = 0;
for(int k = 0; k <= N; k++) {
for(int i = 0; i <= N; i++) {
for(int j = N + 1; j >= i + 1; j--) {
if(i - 1 >= 0) {
if(k - 1 >= 0 and dp1[i - 1][j][k - 1] + X[i] - X[i - 1] <= T[i]) {
dp1[i][j][k] = min(dp1[i][j][k], dp1[i - 1][j][k - 1] + X[i] - X[i - 1]);
}
if(dp1[i - 1][j][k] + X[i] - X[i - 1] > T[i]) {
dp1[i][j][k] = min(dp1[i][j][k], dp1[i - 1][j][k] + X[i] - X[i - 1]);
}
if(k - 1 >= 0 and dp2[i - 1][j][k - 1] + (L - X[j]) + X[i] <= T[i]) {
dp1[i][j][k] = min(dp1[i][j][k], dp2[i - 1][j][k - 1] + (L - X[j]) + X[i]);
}
if(dp2[i - 1][j][k] + (L - X[j]) + X[i] > T[i]) {
dp1[i][j][k] = min(dp1[i][j][k], dp2[i - 1][j][k] + (L - X[j]) + X[i]);
}
}
if(j + 1 <= N + 1) {
if(k - 1 >= 0 and dp2[i][j + 1][k - 1] + X[j + 1] - X[j] <= T[j]) {
dp2[i][j][k] = min(dp2[i][j][k], dp2[i][j + 1][k - 1] + X[j + 1] - X[j]);
}
if(dp2[i][j + 1][k] + X[j + 1] - X[j] > T[j]) {
dp2[i][j][k] = min(dp2[i][j][k], dp2[i][j + 1][k] + X[j + 1] - X[j]);
}
if(k - 1 >= 0 and dp1[i][j + 1][k - 1] + (L - X[j]) + X[i] <= T[j]) {
dp2[i][j][k] = min(dp2[i][j][k], dp1[i][j + 1][k - 1] + (L - X[j]) + X[i]);
}
if(dp1[i][j + 1][k] + (L - X[j]) + X[i] > T[j]) {
dp2[i][j][k] = min(dp2[i][j][k], dp1[i][j + 1][k] + (L - X[j]) + X[i]);
}
}
if(dp1[i][j][k] != llINF or dp2[i][j][k] != llINF) {
ans = k;
}
}
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
964 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
964 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
1224 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
972 KB |
Output is correct |
21 |
Correct |
1 ms |
1224 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
1352 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1236 KB |
Output is correct |
26 |
Correct |
1 ms |
1224 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
1364 KB |
Output is correct |
30 |
Correct |
1 ms |
1348 KB |
Output is correct |
31 |
Correct |
1 ms |
1236 KB |
Output is correct |
32 |
Correct |
1 ms |
1088 KB |
Output is correct |
33 |
Correct |
1 ms |
1236 KB |
Output is correct |
34 |
Correct |
1 ms |
1364 KB |
Output is correct |
35 |
Correct |
1 ms |
1236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
964 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
145 ms |
106924 KB |
Output is correct |
19 |
Correct |
88 ms |
65152 KB |
Output is correct |
20 |
Correct |
45 ms |
35028 KB |
Output is correct |
21 |
Correct |
77 ms |
61548 KB |
Output is correct |
22 |
Correct |
91 ms |
79500 KB |
Output is correct |
23 |
Correct |
26 ms |
29832 KB |
Output is correct |
24 |
Correct |
26 ms |
23532 KB |
Output is correct |
25 |
Correct |
35 ms |
29268 KB |
Output is correct |
26 |
Correct |
9 ms |
11476 KB |
Output is correct |
27 |
Correct |
33 ms |
30540 KB |
Output is correct |
28 |
Correct |
18 ms |
21876 KB |
Output is correct |
29 |
Correct |
29 ms |
31180 KB |
Output is correct |
30 |
Correct |
21 ms |
24532 KB |
Output is correct |
31 |
Correct |
26 ms |
29268 KB |
Output is correct |
32 |
Correct |
13 ms |
15572 KB |
Output is correct |
33 |
Correct |
29 ms |
29224 KB |
Output is correct |
34 |
Correct |
8 ms |
10708 KB |
Output is correct |
35 |
Correct |
31 ms |
28728 KB |
Output is correct |
36 |
Correct |
10 ms |
13780 KB |
Output is correct |
37 |
Correct |
27 ms |
30548 KB |
Output is correct |
38 |
Correct |
14 ms |
16980 KB |
Output is correct |
39 |
Correct |
32 ms |
31740 KB |
Output is correct |
40 |
Correct |
16 ms |
18992 KB |
Output is correct |
41 |
Correct |
227 ms |
131560 KB |
Output is correct |
42 |
Correct |
133 ms |
88936 KB |
Output is correct |
43 |
Correct |
207 ms |
131568 KB |
Output is correct |
44 |
Correct |
105 ms |
87872 KB |
Output is correct |
45 |
Correct |
206 ms |
131552 KB |
Output is correct |
46 |
Correct |
106 ms |
88948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
852 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
980 KB |
Output is correct |
13 |
Correct |
1 ms |
964 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
980 KB |
Output is correct |
17 |
Correct |
1 ms |
980 KB |
Output is correct |
18 |
Correct |
1 ms |
1224 KB |
Output is correct |
19 |
Correct |
1 ms |
852 KB |
Output is correct |
20 |
Correct |
1 ms |
972 KB |
Output is correct |
21 |
Correct |
1 ms |
1224 KB |
Output is correct |
22 |
Correct |
1 ms |
724 KB |
Output is correct |
23 |
Correct |
1 ms |
1352 KB |
Output is correct |
24 |
Correct |
1 ms |
1108 KB |
Output is correct |
25 |
Correct |
1 ms |
1236 KB |
Output is correct |
26 |
Correct |
1 ms |
1224 KB |
Output is correct |
27 |
Correct |
1 ms |
596 KB |
Output is correct |
28 |
Correct |
1 ms |
724 KB |
Output is correct |
29 |
Correct |
1 ms |
1364 KB |
Output is correct |
30 |
Correct |
1 ms |
1348 KB |
Output is correct |
31 |
Correct |
1 ms |
1236 KB |
Output is correct |
32 |
Correct |
1 ms |
1088 KB |
Output is correct |
33 |
Correct |
1 ms |
1236 KB |
Output is correct |
34 |
Correct |
1 ms |
1364 KB |
Output is correct |
35 |
Correct |
1 ms |
1236 KB |
Output is correct |
36 |
Correct |
145 ms |
106924 KB |
Output is correct |
37 |
Correct |
88 ms |
65152 KB |
Output is correct |
38 |
Correct |
45 ms |
35028 KB |
Output is correct |
39 |
Correct |
77 ms |
61548 KB |
Output is correct |
40 |
Correct |
91 ms |
79500 KB |
Output is correct |
41 |
Correct |
26 ms |
29832 KB |
Output is correct |
42 |
Correct |
26 ms |
23532 KB |
Output is correct |
43 |
Correct |
35 ms |
29268 KB |
Output is correct |
44 |
Correct |
9 ms |
11476 KB |
Output is correct |
45 |
Correct |
33 ms |
30540 KB |
Output is correct |
46 |
Correct |
18 ms |
21876 KB |
Output is correct |
47 |
Correct |
29 ms |
31180 KB |
Output is correct |
48 |
Correct |
21 ms |
24532 KB |
Output is correct |
49 |
Correct |
26 ms |
29268 KB |
Output is correct |
50 |
Correct |
13 ms |
15572 KB |
Output is correct |
51 |
Correct |
29 ms |
29224 KB |
Output is correct |
52 |
Correct |
8 ms |
10708 KB |
Output is correct |
53 |
Correct |
31 ms |
28728 KB |
Output is correct |
54 |
Correct |
10 ms |
13780 KB |
Output is correct |
55 |
Correct |
27 ms |
30548 KB |
Output is correct |
56 |
Correct |
14 ms |
16980 KB |
Output is correct |
57 |
Correct |
32 ms |
31740 KB |
Output is correct |
58 |
Correct |
16 ms |
18992 KB |
Output is correct |
59 |
Correct |
227 ms |
131560 KB |
Output is correct |
60 |
Correct |
133 ms |
88936 KB |
Output is correct |
61 |
Correct |
207 ms |
131568 KB |
Output is correct |
62 |
Correct |
105 ms |
87872 KB |
Output is correct |
63 |
Correct |
206 ms |
131552 KB |
Output is correct |
64 |
Correct |
106 ms |
88948 KB |
Output is correct |
65 |
Correct |
174 ms |
118884 KB |
Output is correct |
66 |
Correct |
198 ms |
109160 KB |
Output is correct |
67 |
Correct |
138 ms |
104536 KB |
Output is correct |
68 |
Correct |
124 ms |
96608 KB |
Output is correct |
69 |
Correct |
196 ms |
117560 KB |
Output is correct |
70 |
Correct |
200 ms |
112820 KB |
Output is correct |
71 |
Correct |
159 ms |
113996 KB |
Output is correct |
72 |
Correct |
171 ms |
115196 KB |
Output is correct |
73 |
Correct |
152 ms |
106864 KB |
Output is correct |
74 |
Correct |
137 ms |
99944 KB |
Output is correct |
75 |
Correct |
162 ms |
110396 KB |
Output is correct |
76 |
Correct |
217 ms |
126428 KB |
Output is correct |
77 |
Correct |
195 ms |
126348 KB |
Output is correct |
78 |
Correct |
133 ms |
97696 KB |
Output is correct |
79 |
Correct |
138 ms |
101080 KB |
Output is correct |
80 |
Correct |
186 ms |
123984 KB |
Output is correct |
81 |
Correct |
151 ms |
102228 KB |
Output is correct |
82 |
Correct |
160 ms |
108036 KB |
Output is correct |
83 |
Correct |
252 ms |
131600 KB |
Output is correct |
84 |
Correct |
160 ms |
112736 KB |
Output is correct |
85 |
Correct |
193 ms |
122596 KB |
Output is correct |
86 |
Correct |
195 ms |
120204 KB |
Output is correct |
87 |
Correct |
174 ms |
110400 KB |
Output is correct |
88 |
Correct |
254 ms |
132776 KB |
Output is correct |
89 |
Correct |
225 ms |
132868 KB |
Output is correct |
90 |
Correct |
177 ms |
111548 KB |
Output is correct |
91 |
Correct |
226 ms |
132868 KB |
Output is correct |
92 |
Correct |
199 ms |
132864 KB |
Output is correct |
93 |
Correct |
209 ms |
130380 KB |
Output is correct |