#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll = long long;
int n, L;
const int MAXN = 205;
ll dp[MAXN][MAXN][2][MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> L;
vector <ll> x(n + 2), t(n + 2);
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 i = 0; i <= n + 1; i++) {
for(int j = 0; j <= n + 1; j++) {
for(int k = 0; k < 2; k++) {
for(int m = 0; m <= n; m++) dp[i][j][k][m] = 1e18;
}
}
}
dp[0][n + 1][0][0] = dp[0][n + 1][1][0] = 0;
for(int i = 0; i < n; i++) {
for(int j = n + 1; j >= i + 2; j--) {
for(int m = 0; m <= n; m++) {
ll T;
T = min(dp[i][j][0][m] + x[i + 1] - x[i], dp[i][j][1][m] + x[i + 1] + L - x[j]);
dp[i + 1][j][0][m + (T <= t[i + 1])] = min(dp[i + 1][j][0][m + (T <= t[i + 1])], T);
T = min(dp[i][j][0][m] + x[i] + L - x[j - 1], dp[i][j][1][m] + x[j] - x[j - 1]);
dp[i][j - 1][1][m + (T <= t[j - 1])] = min(dp[i][j - 1][1][m + (T <= t[j - 1])], T);
}
}
}
ll ans = 0;
for(int i = 0; i <= n + 1; i++) {
for(int j = 0; j <= n + 1; j++) {
for(int k = 0; k < 2; k++) {
for(int m = 0; m <= n; m++) {
if(dp[i][j][k][m] != 1e18) ans = max(ans, (ll)m);
}
}
}
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
712 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 |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
328 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 |
584 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 |
968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
712 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 |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
328 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 |
584 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 |
968 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
708 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
1096 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 |
1236 KB |
Output is correct |
30 |
Correct |
1 ms |
1236 KB |
Output is correct |
31 |
Correct |
1 ms |
1108 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
1236 KB |
Output is correct |
34 |
Correct |
2 ms |
1236 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 |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
712 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 |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
328 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 |
584 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 |
968 KB |
Output is correct |
18 |
Correct |
103 ms |
106184 KB |
Output is correct |
19 |
Correct |
59 ms |
64656 KB |
Output is correct |
20 |
Correct |
29 ms |
34700 KB |
Output is correct |
21 |
Correct |
55 ms |
60988 KB |
Output is correct |
22 |
Correct |
79 ms |
79012 KB |
Output is correct |
23 |
Correct |
23 ms |
29524 KB |
Output is correct |
24 |
Correct |
17 ms |
23244 KB |
Output is correct |
25 |
Correct |
23 ms |
29012 KB |
Output is correct |
26 |
Correct |
8 ms |
11332 KB |
Output is correct |
27 |
Correct |
24 ms |
30164 KB |
Output is correct |
28 |
Correct |
17 ms |
21680 KB |
Output is correct |
29 |
Correct |
24 ms |
30768 KB |
Output is correct |
30 |
Correct |
22 ms |
24404 KB |
Output is correct |
31 |
Correct |
23 ms |
28968 KB |
Output is correct |
32 |
Correct |
11 ms |
15352 KB |
Output is correct |
33 |
Correct |
23 ms |
29012 KB |
Output is correct |
34 |
Correct |
7 ms |
10580 KB |
Output is correct |
35 |
Correct |
22 ms |
28372 KB |
Output is correct |
36 |
Correct |
10 ms |
13652 KB |
Output is correct |
37 |
Correct |
24 ms |
30220 KB |
Output is correct |
38 |
Correct |
12 ms |
16724 KB |
Output is correct |
39 |
Correct |
24 ms |
31444 KB |
Output is correct |
40 |
Correct |
14 ms |
18644 KB |
Output is correct |
41 |
Correct |
147 ms |
130836 KB |
Output is correct |
42 |
Correct |
79 ms |
88332 KB |
Output is correct |
43 |
Correct |
140 ms |
130856 KB |
Output is correct |
44 |
Correct |
74 ms |
87184 KB |
Output is correct |
45 |
Correct |
137 ms |
130764 KB |
Output is correct |
46 |
Correct |
83 ms |
88268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
712 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 |
724 KB |
Output is correct |
9 |
Correct |
1 ms |
980 KB |
Output is correct |
10 |
Correct |
1 ms |
328 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 |
584 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 |
968 KB |
Output is correct |
18 |
Correct |
1 ms |
1108 KB |
Output is correct |
19 |
Correct |
1 ms |
724 KB |
Output is correct |
20 |
Correct |
1 ms |
980 KB |
Output is correct |
21 |
Correct |
1 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
708 KB |
Output is correct |
23 |
Correct |
1 ms |
1236 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
1 ms |
1108 KB |
Output is correct |
26 |
Correct |
1 ms |
1096 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 |
1236 KB |
Output is correct |
30 |
Correct |
1 ms |
1236 KB |
Output is correct |
31 |
Correct |
1 ms |
1108 KB |
Output is correct |
32 |
Correct |
1 ms |
980 KB |
Output is correct |
33 |
Correct |
1 ms |
1236 KB |
Output is correct |
34 |
Correct |
2 ms |
1236 KB |
Output is correct |
35 |
Correct |
1 ms |
1236 KB |
Output is correct |
36 |
Correct |
103 ms |
106184 KB |
Output is correct |
37 |
Correct |
59 ms |
64656 KB |
Output is correct |
38 |
Correct |
29 ms |
34700 KB |
Output is correct |
39 |
Correct |
55 ms |
60988 KB |
Output is correct |
40 |
Correct |
79 ms |
79012 KB |
Output is correct |
41 |
Correct |
23 ms |
29524 KB |
Output is correct |
42 |
Correct |
17 ms |
23244 KB |
Output is correct |
43 |
Correct |
23 ms |
29012 KB |
Output is correct |
44 |
Correct |
8 ms |
11332 KB |
Output is correct |
45 |
Correct |
24 ms |
30164 KB |
Output is correct |
46 |
Correct |
17 ms |
21680 KB |
Output is correct |
47 |
Correct |
24 ms |
30768 KB |
Output is correct |
48 |
Correct |
22 ms |
24404 KB |
Output is correct |
49 |
Correct |
23 ms |
28968 KB |
Output is correct |
50 |
Correct |
11 ms |
15352 KB |
Output is correct |
51 |
Correct |
23 ms |
29012 KB |
Output is correct |
52 |
Correct |
7 ms |
10580 KB |
Output is correct |
53 |
Correct |
22 ms |
28372 KB |
Output is correct |
54 |
Correct |
10 ms |
13652 KB |
Output is correct |
55 |
Correct |
24 ms |
30220 KB |
Output is correct |
56 |
Correct |
12 ms |
16724 KB |
Output is correct |
57 |
Correct |
24 ms |
31444 KB |
Output is correct |
58 |
Correct |
14 ms |
18644 KB |
Output is correct |
59 |
Correct |
147 ms |
130836 KB |
Output is correct |
60 |
Correct |
79 ms |
88332 KB |
Output is correct |
61 |
Correct |
140 ms |
130856 KB |
Output is correct |
62 |
Correct |
74 ms |
87184 KB |
Output is correct |
63 |
Correct |
137 ms |
130764 KB |
Output is correct |
64 |
Correct |
83 ms |
88268 KB |
Output is correct |
65 |
Correct |
120 ms |
118156 KB |
Output is correct |
66 |
Correct |
109 ms |
108476 KB |
Output is correct |
67 |
Correct |
104 ms |
103804 KB |
Output is correct |
68 |
Correct |
94 ms |
95948 KB |
Output is correct |
69 |
Correct |
108 ms |
116924 KB |
Output is correct |
70 |
Correct |
116 ms |
111964 KB |
Output is correct |
71 |
Correct |
113 ms |
113232 KB |
Output is correct |
72 |
Correct |
112 ms |
114488 KB |
Output is correct |
73 |
Correct |
101 ms |
106156 KB |
Output is correct |
74 |
Correct |
97 ms |
99364 KB |
Output is correct |
75 |
Correct |
109 ms |
109772 KB |
Output is correct |
76 |
Correct |
132 ms |
125692 KB |
Output is correct |
77 |
Correct |
129 ms |
125664 KB |
Output is correct |
78 |
Correct |
93 ms |
96972 KB |
Output is correct |
79 |
Correct |
98 ms |
100300 KB |
Output is correct |
80 |
Correct |
124 ms |
123056 KB |
Output is correct |
81 |
Correct |
97 ms |
101568 KB |
Output is correct |
82 |
Correct |
104 ms |
107380 KB |
Output is correct |
83 |
Correct |
136 ms |
130664 KB |
Output is correct |
84 |
Correct |
109 ms |
112072 KB |
Output is correct |
85 |
Correct |
124 ms |
121868 KB |
Output is correct |
86 |
Correct |
119 ms |
119344 KB |
Output is correct |
87 |
Correct |
109 ms |
109620 KB |
Output is correct |
88 |
Correct |
139 ms |
132068 KB |
Output is correct |
89 |
Correct |
140 ms |
132076 KB |
Output is correct |
90 |
Correct |
100 ms |
110868 KB |
Output is correct |
91 |
Correct |
147 ms |
131996 KB |
Output is correct |
92 |
Correct |
143 ms |
132076 KB |
Output is correct |
93 |
Correct |
136 ms |
129356 KB |
Output is correct |