#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 210, inf = 1e9 + 1;
int dp[N][N][N][2], X[N], T[N];
int32_t main()
{
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];
for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= n + 1; j++) for (int c = 0; c <= n; c++) dp[i][j][c][0] = dp[i][j][c][1] = inf;
T[0] = T[n+1] = -1;
X[n+1] = L;
dp[0][n+1][0][0] = dp[0][n+1][0][1] = 0;
int ans = 0;
for (int c = 0; c <= n; c++) {
for (int i = 0; i <= n; i++) {
for (int j = n + 1; j > i; j--) {
if (i > 0) {
dp[i][j][c][0] = min(dp[i][j][c][0], min(dp[i - 1][j][c][0] + X[i] - X[i - 1], dp[i - 1][j][c][1] + X[i] + L - X[j]));
if (c > 0 && dp[i - 1][j][c - 1][0] + X[i] - X[i - 1] <= T[i])
dp[i][j][c][0] = min(dp[i][j][c][0], dp[i - 1][j][c - 1][0] + X[i] - X[i - 1]);
if (c > 0 && dp[i - 1][j][c - 1][1] + X[i] + L - X[j] <= T[i])
dp[i][j][c][0] = min(dp[i][j][c][0], dp[i - 1][j][c - 1][1] + X[i] + L - X[j]);
}
if (j < n + 1) {
dp[i][j][c][1] = min(dp[i][j][c][1], min(dp[i][j + 1][c][1] + X[j + 1] - X[j], dp[i][j + 1][c][0] + X[i] + L - X[j]));
if (c > 0 && dp[i][j + 1][c - 1][1] + X[j + 1] - X[j] <= T[j])
dp[i][j][c][1] = min(dp[i][j][c][1], dp[i][j + 1][c - 1][1] + X[j + 1] - X[j]);
if (c > 0 && dp[i][j + 1][c - 1][0] + X[i] + L - X[j] <= T[j])
dp[i][j][c][1] = min(dp[i][j][c][1], dp[i][j + 1][c - 1][0] + X[i] + L - X[j]);
}
if (dp[i][j][c][0] < inf || dp[i][j][c][1] < inf) ans = c;
}
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
760 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
1016 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
1016 KB |
Output is correct |
17 |
Correct |
5 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
760 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
1016 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
1016 KB |
Output is correct |
17 |
Correct |
5 ms |
1016 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
1016 KB |
Output is correct |
21 |
Correct |
5 ms |
1144 KB |
Output is correct |
22 |
Correct |
5 ms |
760 KB |
Output is correct |
23 |
Correct |
5 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
1144 KB |
Output is correct |
26 |
Correct |
5 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
1272 KB |
Output is correct |
30 |
Correct |
5 ms |
1272 KB |
Output is correct |
31 |
Correct |
5 ms |
1144 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
1276 KB |
Output is correct |
34 |
Correct |
6 ms |
1272 KB |
Output is correct |
35 |
Correct |
5 ms |
1276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
760 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
1016 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
1016 KB |
Output is correct |
17 |
Correct |
5 ms |
1016 KB |
Output is correct |
18 |
Correct |
136 ms |
108792 KB |
Output is correct |
19 |
Correct |
64 ms |
66168 KB |
Output is correct |
20 |
Correct |
32 ms |
35448 KB |
Output is correct |
21 |
Correct |
60 ms |
62456 KB |
Output is correct |
22 |
Correct |
81 ms |
80912 KB |
Output is correct |
23 |
Correct |
28 ms |
30200 KB |
Output is correct |
24 |
Correct |
21 ms |
23800 KB |
Output is correct |
25 |
Correct |
27 ms |
29688 KB |
Output is correct |
26 |
Correct |
12 ms |
11512 KB |
Output is correct |
27 |
Correct |
29 ms |
30972 KB |
Output is correct |
28 |
Correct |
21 ms |
22160 KB |
Output is correct |
29 |
Correct |
30 ms |
31608 KB |
Output is correct |
30 |
Correct |
22 ms |
24824 KB |
Output is correct |
31 |
Correct |
28 ms |
29688 KB |
Output is correct |
32 |
Correct |
15 ms |
15736 KB |
Output is correct |
33 |
Correct |
27 ms |
29688 KB |
Output is correct |
34 |
Correct |
12 ms |
10744 KB |
Output is correct |
35 |
Correct |
27 ms |
29048 KB |
Output is correct |
36 |
Correct |
15 ms |
13944 KB |
Output is correct |
37 |
Correct |
28 ms |
30840 KB |
Output is correct |
38 |
Correct |
17 ms |
17144 KB |
Output is correct |
39 |
Correct |
29 ms |
32120 KB |
Output is correct |
40 |
Correct |
18 ms |
19180 KB |
Output is correct |
41 |
Correct |
148 ms |
133880 KB |
Output is correct |
42 |
Correct |
94 ms |
90360 KB |
Output is correct |
43 |
Correct |
151 ms |
134016 KB |
Output is correct |
44 |
Correct |
90 ms |
89336 KB |
Output is correct |
45 |
Correct |
149 ms |
133880 KB |
Output is correct |
46 |
Correct |
95 ms |
90360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
760 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
1016 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
1016 KB |
Output is correct |
17 |
Correct |
5 ms |
1016 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
1016 KB |
Output is correct |
21 |
Correct |
5 ms |
1144 KB |
Output is correct |
22 |
Correct |
5 ms |
760 KB |
Output is correct |
23 |
Correct |
5 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
1144 KB |
Output is correct |
26 |
Correct |
5 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
1272 KB |
Output is correct |
30 |
Correct |
5 ms |
1272 KB |
Output is correct |
31 |
Correct |
5 ms |
1144 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
1276 KB |
Output is correct |
34 |
Correct |
6 ms |
1272 KB |
Output is correct |
35 |
Correct |
5 ms |
1276 KB |
Output is correct |
36 |
Correct |
136 ms |
108792 KB |
Output is correct |
37 |
Correct |
64 ms |
66168 KB |
Output is correct |
38 |
Correct |
32 ms |
35448 KB |
Output is correct |
39 |
Correct |
60 ms |
62456 KB |
Output is correct |
40 |
Correct |
81 ms |
80912 KB |
Output is correct |
41 |
Correct |
28 ms |
30200 KB |
Output is correct |
42 |
Correct |
21 ms |
23800 KB |
Output is correct |
43 |
Correct |
27 ms |
29688 KB |
Output is correct |
44 |
Correct |
12 ms |
11512 KB |
Output is correct |
45 |
Correct |
29 ms |
30972 KB |
Output is correct |
46 |
Correct |
21 ms |
22160 KB |
Output is correct |
47 |
Correct |
30 ms |
31608 KB |
Output is correct |
48 |
Correct |
22 ms |
24824 KB |
Output is correct |
49 |
Correct |
28 ms |
29688 KB |
Output is correct |
50 |
Correct |
15 ms |
15736 KB |
Output is correct |
51 |
Correct |
27 ms |
29688 KB |
Output is correct |
52 |
Correct |
12 ms |
10744 KB |
Output is correct |
53 |
Correct |
27 ms |
29048 KB |
Output is correct |
54 |
Correct |
15 ms |
13944 KB |
Output is correct |
55 |
Correct |
28 ms |
30840 KB |
Output is correct |
56 |
Correct |
17 ms |
17144 KB |
Output is correct |
57 |
Correct |
29 ms |
32120 KB |
Output is correct |
58 |
Correct |
18 ms |
19180 KB |
Output is correct |
59 |
Correct |
148 ms |
133880 KB |
Output is correct |
60 |
Correct |
94 ms |
90360 KB |
Output is correct |
61 |
Correct |
151 ms |
134016 KB |
Output is correct |
62 |
Correct |
90 ms |
89336 KB |
Output is correct |
63 |
Correct |
149 ms |
133880 KB |
Output is correct |
64 |
Correct |
95 ms |
90360 KB |
Output is correct |
65 |
Correct |
131 ms |
121080 KB |
Output is correct |
66 |
Correct |
116 ms |
111096 KB |
Output is correct |
67 |
Correct |
111 ms |
106508 KB |
Output is correct |
68 |
Correct |
103 ms |
98296 KB |
Output is correct |
69 |
Correct |
137 ms |
119928 KB |
Output is correct |
70 |
Correct |
123 ms |
114808 KB |
Output is correct |
71 |
Correct |
132 ms |
115960 KB |
Output is correct |
72 |
Correct |
128 ms |
117240 KB |
Output is correct |
73 |
Correct |
114 ms |
108792 KB |
Output is correct |
74 |
Correct |
104 ms |
101624 KB |
Output is correct |
75 |
Correct |
122 ms |
112248 KB |
Output is correct |
76 |
Correct |
143 ms |
128632 KB |
Output is correct |
77 |
Correct |
137 ms |
128632 KB |
Output is correct |
78 |
Correct |
103 ms |
99280 KB |
Output is correct |
79 |
Correct |
108 ms |
102776 KB |
Output is correct |
80 |
Correct |
136 ms |
126200 KB |
Output is correct |
81 |
Correct |
109 ms |
104092 KB |
Output is correct |
82 |
Correct |
116 ms |
109944 KB |
Output is correct |
83 |
Correct |
151 ms |
133960 KB |
Output is correct |
84 |
Correct |
125 ms |
114936 KB |
Output is correct |
85 |
Correct |
140 ms |
124792 KB |
Output is correct |
86 |
Correct |
133 ms |
122232 KB |
Output is correct |
87 |
Correct |
118 ms |
112248 KB |
Output is correct |
88 |
Correct |
149 ms |
135312 KB |
Output is correct |
89 |
Correct |
160 ms |
135288 KB |
Output is correct |
90 |
Correct |
125 ms |
113528 KB |
Output is correct |
91 |
Correct |
164 ms |
135288 KB |
Output is correct |
92 |
Correct |
151 ms |
135416 KB |
Output is correct |
93 |
Correct |
150 ms |
132728 KB |
Output is correct |