#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 205, inf = 1e9 + 7;
int n, l;
int x[N], t[N], dp[N][N][N][2];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
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 = 0; j <= n + 1; ++j) {
for (int k = 0; k <= n; ++k) {
for (int x = 0; x < 2; ++x) {
dp[i][j][k][x] = inf;
}
}
}
}
dp[0][n + 1][0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = n + 1; j > i + 1; --j) {
for (int cnt = 0; cnt <= n; ++cnt) {
if (dp[i][j][cnt][0] != inf) {
int c = dp[i][j][cnt][0] + x[i + 1] - x[i];
int ncnt = cnt + (c <= t[i + 1]);
dp[i + 1][j][ncnt][0] = min(dp[i + 1][j][ncnt][0], c);
c = dp[i][j][cnt][0] + x[i] + l - x[j - 1];
ncnt = cnt + (c <= t[j - 1]);
dp[i][j - 1][ncnt][1] = min(dp[i][j - 1][ncnt][1], c);
}
if (dp[i][j][cnt][1] != inf) {
int c = dp[i][j][cnt][1] + l - x[j] + x[i + 1];
int ncnt = cnt + (c <= t[i + 1]);
dp[i + 1][j][ncnt][0] = min(dp[i + 1][j][ncnt][0], c);
c = dp[i][j][cnt][1] + x[j] - x[j - 1];
ncnt = cnt + (c <= t[j - 1]);
dp[i][j - 1][ncnt][1] = min(dp[i][j - 1][ncnt][1], c);
}
}
}
}
int res = 0;
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n + 1; ++j) {
for (int k = 0; k <= n; ++k) {
for (int x = 0; x < 2; ++x) {
if (dp[i][j][k][x] < inf) {
res = max(res, k);
}
}
}
}
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
608 KB |
Output is correct |
7 |
Correct |
0 ms |
612 KB |
Output is correct |
8 |
Correct |
0 ms |
608 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
720 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
856 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
608 KB |
Output is correct |
7 |
Correct |
0 ms |
612 KB |
Output is correct |
8 |
Correct |
0 ms |
608 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
720 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
856 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
860 KB |
Output is correct |
19 |
Correct |
0 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
1112 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
0 ms |
860 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
716 KB |
Output is correct |
26 |
Correct |
1 ms |
860 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
0 ms |
604 KB |
Output is correct |
29 |
Correct |
0 ms |
860 KB |
Output is correct |
30 |
Correct |
0 ms |
860 KB |
Output is correct |
31 |
Correct |
1 ms |
864 KB |
Output is correct |
32 |
Correct |
0 ms |
600 KB |
Output is correct |
33 |
Correct |
0 ms |
860 KB |
Output is correct |
34 |
Correct |
1 ms |
860 KB |
Output is correct |
35 |
Correct |
0 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
608 KB |
Output is correct |
7 |
Correct |
0 ms |
612 KB |
Output is correct |
8 |
Correct |
0 ms |
608 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
720 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
856 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
38 ms |
53276 KB |
Output is correct |
19 |
Correct |
23 ms |
32604 KB |
Output is correct |
20 |
Correct |
12 ms |
17500 KB |
Output is correct |
21 |
Correct |
22 ms |
30812 KB |
Output is correct |
22 |
Correct |
28 ms |
39772 KB |
Output is correct |
23 |
Correct |
10 ms |
15108 KB |
Output is correct |
24 |
Correct |
7 ms |
11868 KB |
Output is correct |
25 |
Correct |
9 ms |
14816 KB |
Output is correct |
26 |
Correct |
3 ms |
5912 KB |
Output is correct |
27 |
Correct |
9 ms |
15196 KB |
Output is correct |
28 |
Correct |
7 ms |
11108 KB |
Output is correct |
29 |
Correct |
10 ms |
15716 KB |
Output is correct |
30 |
Correct |
6 ms |
12380 KB |
Output is correct |
31 |
Correct |
8 ms |
14684 KB |
Output is correct |
32 |
Correct |
4 ms |
7776 KB |
Output is correct |
33 |
Correct |
8 ms |
14724 KB |
Output is correct |
34 |
Correct |
3 ms |
5468 KB |
Output is correct |
35 |
Correct |
9 ms |
14500 KB |
Output is correct |
36 |
Correct |
4 ms |
7004 KB |
Output is correct |
37 |
Correct |
9 ms |
15312 KB |
Output is correct |
38 |
Correct |
5 ms |
8496 KB |
Output is correct |
39 |
Correct |
10 ms |
15964 KB |
Output is correct |
40 |
Correct |
5 ms |
9612 KB |
Output is correct |
41 |
Correct |
48 ms |
65652 KB |
Output is correct |
42 |
Correct |
26 ms |
44380 KB |
Output is correct |
43 |
Correct |
49 ms |
65624 KB |
Output is correct |
44 |
Correct |
26 ms |
43936 KB |
Output is correct |
45 |
Correct |
51 ms |
65724 KB |
Output is correct |
46 |
Correct |
31 ms |
44624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
608 KB |
Output is correct |
7 |
Correct |
0 ms |
612 KB |
Output is correct |
8 |
Correct |
0 ms |
608 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
720 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
0 ms |
856 KB |
Output is correct |
17 |
Correct |
0 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
860 KB |
Output is correct |
19 |
Correct |
0 ms |
856 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
1112 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
0 ms |
860 KB |
Output is correct |
24 |
Correct |
0 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
716 KB |
Output is correct |
26 |
Correct |
1 ms |
860 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
0 ms |
604 KB |
Output is correct |
29 |
Correct |
0 ms |
860 KB |
Output is correct |
30 |
Correct |
0 ms |
860 KB |
Output is correct |
31 |
Correct |
1 ms |
864 KB |
Output is correct |
32 |
Correct |
0 ms |
600 KB |
Output is correct |
33 |
Correct |
0 ms |
860 KB |
Output is correct |
34 |
Correct |
1 ms |
860 KB |
Output is correct |
35 |
Correct |
0 ms |
860 KB |
Output is correct |
36 |
Correct |
38 ms |
53276 KB |
Output is correct |
37 |
Correct |
23 ms |
32604 KB |
Output is correct |
38 |
Correct |
12 ms |
17500 KB |
Output is correct |
39 |
Correct |
22 ms |
30812 KB |
Output is correct |
40 |
Correct |
28 ms |
39772 KB |
Output is correct |
41 |
Correct |
10 ms |
15108 KB |
Output is correct |
42 |
Correct |
7 ms |
11868 KB |
Output is correct |
43 |
Correct |
9 ms |
14816 KB |
Output is correct |
44 |
Correct |
3 ms |
5912 KB |
Output is correct |
45 |
Correct |
9 ms |
15196 KB |
Output is correct |
46 |
Correct |
7 ms |
11108 KB |
Output is correct |
47 |
Correct |
10 ms |
15716 KB |
Output is correct |
48 |
Correct |
6 ms |
12380 KB |
Output is correct |
49 |
Correct |
8 ms |
14684 KB |
Output is correct |
50 |
Correct |
4 ms |
7776 KB |
Output is correct |
51 |
Correct |
8 ms |
14724 KB |
Output is correct |
52 |
Correct |
3 ms |
5468 KB |
Output is correct |
53 |
Correct |
9 ms |
14500 KB |
Output is correct |
54 |
Correct |
4 ms |
7004 KB |
Output is correct |
55 |
Correct |
9 ms |
15312 KB |
Output is correct |
56 |
Correct |
5 ms |
8496 KB |
Output is correct |
57 |
Correct |
10 ms |
15964 KB |
Output is correct |
58 |
Correct |
5 ms |
9612 KB |
Output is correct |
59 |
Correct |
48 ms |
65652 KB |
Output is correct |
60 |
Correct |
26 ms |
44380 KB |
Output is correct |
61 |
Correct |
49 ms |
65624 KB |
Output is correct |
62 |
Correct |
26 ms |
43936 KB |
Output is correct |
63 |
Correct |
51 ms |
65724 KB |
Output is correct |
64 |
Correct |
31 ms |
44624 KB |
Output is correct |
65 |
Correct |
39 ms |
59220 KB |
Output is correct |
66 |
Correct |
38 ms |
54360 KB |
Output is correct |
67 |
Correct |
35 ms |
52060 KB |
Output is correct |
68 |
Correct |
29 ms |
48220 KB |
Output is correct |
69 |
Correct |
38 ms |
58712 KB |
Output is correct |
70 |
Correct |
39 ms |
56144 KB |
Output is correct |
71 |
Correct |
37 ms |
56920 KB |
Output is correct |
72 |
Correct |
40 ms |
57436 KB |
Output is correct |
73 |
Correct |
33 ms |
53340 KB |
Output is correct |
74 |
Correct |
38 ms |
49996 KB |
Output is correct |
75 |
Correct |
37 ms |
55132 KB |
Output is correct |
76 |
Correct |
46 ms |
63060 KB |
Output is correct |
77 |
Correct |
44 ms |
63068 KB |
Output is correct |
78 |
Correct |
33 ms |
48732 KB |
Output is correct |
79 |
Correct |
35 ms |
50728 KB |
Output is correct |
80 |
Correct |
44 ms |
61828 KB |
Output is correct |
81 |
Correct |
33 ms |
51036 KB |
Output is correct |
82 |
Correct |
34 ms |
53980 KB |
Output is correct |
83 |
Correct |
51 ms |
65720 KB |
Output is correct |
84 |
Correct |
38 ms |
56244 KB |
Output is correct |
85 |
Correct |
41 ms |
61236 KB |
Output is correct |
86 |
Correct |
42 ms |
59996 KB |
Output is correct |
87 |
Correct |
41 ms |
55124 KB |
Output is correct |
88 |
Correct |
48 ms |
66248 KB |
Output is correct |
89 |
Correct |
45 ms |
66400 KB |
Output is correct |
90 |
Correct |
45 ms |
55644 KB |
Output is correct |
91 |
Correct |
48 ms |
66388 KB |
Output is correct |
92 |
Correct |
47 ms |
66388 KB |
Output is correct |
93 |
Correct |
48 ms |
64860 KB |
Output is correct |