#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define sc second
#define pb push_back
#define int ll
int dp[210][210][210][2];
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, l; cin >> n >> l;
vector<int> x(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> x[i];
vector<int> t(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> t[i];
auto getd = [&](int i, int j) {
return min(abs(x[i] - x[j]), l - abs(x[i] - x[j]));
};
for (int i = 0; i <= 209; i++) {
for (int j = 0; j <= 209;j++) {
for (int cnt = 0; cnt <= 209; cnt++) {
for (int I = 0; I < 2; I++) dp[i][j][cnt][I] = 1e15;
}
}
}
dp[1][0][1][0] = 0;
dp[1][0][1][1] = 0;
for (int cnt = 2; cnt <= n + 1; cnt++) {
for (int left = 1; left <= cnt; left++) {
int right = cnt - left;
for (int C = 1; C <= cnt; C++) {
auto relax = [&](int side, int val) {
if (val < 1e15) {
dp[left][right][C][side] = min(dp[left][right][C][side], val);
}
};
{
int prev_left = (left == 1 ? n : left - 2);
int prev_right = (right == 0 ? 0 : n - right + 1);
if (dp[left - 1][right][C - 1][0] + getd(prev_left, left - 1) <= t[left - 1]) {
relax(0, dp[left - 1][right][C - 1][0] + getd(prev_left, left - 1));
}
if (dp[left - 1][right][C][0] + getd(prev_left, left - 1) > t[left - 1]) {
relax(0, dp[left - 1][right][C][0] + getd(prev_left, left - 1));
}
if (dp[left - 1][right][C - 1][1] + getd(prev_right, left - 1) <= t[left - 1]) {
relax(0, dp[left - 1][right][C - 1][1] + getd(prev_right, left - 1));
}
if (dp[left - 1][right][C][1] + getd(prev_right, left - 1) > t[left - 1]) {
relax(0, dp[left - 1][right][C][1] + getd(prev_right, left - 1));
}
}
if (right) {
int prev_left = left - 1, prev_right = (right == 1 ? 0 : n - (right - 1) + 1);
int cur = n - right + 1;
if (dp[left][right - 1][C - 1][0] + getd(prev_left, cur) <= t[cur]) {
relax(1, dp[left][right - 1][C - 1][0] + getd(prev_left, cur));
}
if (dp[left][right - 1][C][0] + getd(prev_left, cur) > t[cur]) {
relax(1, dp[left][right - 1][C][0] + getd(prev_left, cur));
}
if (dp[left][right - 1][C - 1][1] + getd(prev_right, cur) <= t[cur]) {
relax(1, dp[left][right - 1][C - 1][1] + getd(prev_right, cur));
}
if (dp[left][right - 1][C][1] + getd(prev_right, cur) > t[cur]) {
relax(1, dp[left][right - 1][C][1] + getd(prev_right, cur));
}
}
}
}
}
int ans = 0;
for (int left = 1; left <= n + 1; left++) {
for (int cnt = 1; cnt <= n + 1; cnt++) {
if (dp[left][n + 1 - left][cnt][0] < 1e15 || dp[left][n + 1 - left][cnt][1] < 1e15) ans = max(ans, cnt);
}
}
cout << ans - 1 << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
145232 KB |
Output is correct |
2 |
Correct |
42 ms |
145300 KB |
Output is correct |
3 |
Correct |
42 ms |
145272 KB |
Output is correct |
4 |
Correct |
43 ms |
145404 KB |
Output is correct |
5 |
Correct |
41 ms |
145236 KB |
Output is correct |
6 |
Correct |
40 ms |
145244 KB |
Output is correct |
7 |
Correct |
42 ms |
145344 KB |
Output is correct |
8 |
Correct |
43 ms |
145232 KB |
Output is correct |
9 |
Correct |
41 ms |
145352 KB |
Output is correct |
10 |
Correct |
52 ms |
145236 KB |
Output is correct |
11 |
Correct |
42 ms |
145236 KB |
Output is correct |
12 |
Correct |
42 ms |
145240 KB |
Output is correct |
13 |
Correct |
42 ms |
145244 KB |
Output is correct |
14 |
Correct |
42 ms |
145232 KB |
Output is correct |
15 |
Correct |
41 ms |
145236 KB |
Output is correct |
16 |
Correct |
42 ms |
145212 KB |
Output is correct |
17 |
Correct |
40 ms |
145244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
145232 KB |
Output is correct |
2 |
Correct |
42 ms |
145300 KB |
Output is correct |
3 |
Correct |
42 ms |
145272 KB |
Output is correct |
4 |
Correct |
43 ms |
145404 KB |
Output is correct |
5 |
Correct |
41 ms |
145236 KB |
Output is correct |
6 |
Correct |
40 ms |
145244 KB |
Output is correct |
7 |
Correct |
42 ms |
145344 KB |
Output is correct |
8 |
Correct |
43 ms |
145232 KB |
Output is correct |
9 |
Correct |
41 ms |
145352 KB |
Output is correct |
10 |
Correct |
52 ms |
145236 KB |
Output is correct |
11 |
Correct |
42 ms |
145236 KB |
Output is correct |
12 |
Correct |
42 ms |
145240 KB |
Output is correct |
13 |
Correct |
42 ms |
145244 KB |
Output is correct |
14 |
Correct |
42 ms |
145232 KB |
Output is correct |
15 |
Correct |
41 ms |
145236 KB |
Output is correct |
16 |
Correct |
42 ms |
145212 KB |
Output is correct |
17 |
Correct |
40 ms |
145244 KB |
Output is correct |
18 |
Correct |
41 ms |
145232 KB |
Output is correct |
19 |
Correct |
41 ms |
145244 KB |
Output is correct |
20 |
Correct |
41 ms |
145264 KB |
Output is correct |
21 |
Correct |
42 ms |
145240 KB |
Output is correct |
22 |
Correct |
41 ms |
145232 KB |
Output is correct |
23 |
Correct |
41 ms |
145232 KB |
Output is correct |
24 |
Correct |
44 ms |
145356 KB |
Output is correct |
25 |
Correct |
52 ms |
145232 KB |
Output is correct |
26 |
Correct |
43 ms |
145236 KB |
Output is correct |
27 |
Correct |
42 ms |
145232 KB |
Output is correct |
28 |
Correct |
42 ms |
145232 KB |
Output is correct |
29 |
Correct |
43 ms |
145236 KB |
Output is correct |
30 |
Correct |
41 ms |
145244 KB |
Output is correct |
31 |
Correct |
41 ms |
145408 KB |
Output is correct |
32 |
Correct |
42 ms |
145232 KB |
Output is correct |
33 |
Correct |
41 ms |
145244 KB |
Output is correct |
34 |
Correct |
42 ms |
145308 KB |
Output is correct |
35 |
Correct |
43 ms |
145368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
145232 KB |
Output is correct |
2 |
Correct |
42 ms |
145300 KB |
Output is correct |
3 |
Correct |
42 ms |
145272 KB |
Output is correct |
4 |
Correct |
43 ms |
145404 KB |
Output is correct |
5 |
Correct |
41 ms |
145236 KB |
Output is correct |
6 |
Correct |
40 ms |
145244 KB |
Output is correct |
7 |
Correct |
42 ms |
145344 KB |
Output is correct |
8 |
Correct |
43 ms |
145232 KB |
Output is correct |
9 |
Correct |
41 ms |
145352 KB |
Output is correct |
10 |
Correct |
52 ms |
145236 KB |
Output is correct |
11 |
Correct |
42 ms |
145236 KB |
Output is correct |
12 |
Correct |
42 ms |
145240 KB |
Output is correct |
13 |
Correct |
42 ms |
145244 KB |
Output is correct |
14 |
Correct |
42 ms |
145232 KB |
Output is correct |
15 |
Correct |
41 ms |
145236 KB |
Output is correct |
16 |
Correct |
42 ms |
145212 KB |
Output is correct |
17 |
Correct |
40 ms |
145244 KB |
Output is correct |
18 |
Correct |
65 ms |
145180 KB |
Output is correct |
19 |
Correct |
52 ms |
145256 KB |
Output is correct |
20 |
Correct |
46 ms |
145236 KB |
Output is correct |
21 |
Correct |
58 ms |
145232 KB |
Output is correct |
22 |
Correct |
55 ms |
145232 KB |
Output is correct |
23 |
Correct |
57 ms |
145228 KB |
Output is correct |
24 |
Correct |
57 ms |
145416 KB |
Output is correct |
25 |
Correct |
45 ms |
145268 KB |
Output is correct |
26 |
Correct |
42 ms |
145284 KB |
Output is correct |
27 |
Correct |
44 ms |
145244 KB |
Output is correct |
28 |
Correct |
46 ms |
145236 KB |
Output is correct |
29 |
Correct |
45 ms |
145312 KB |
Output is correct |
30 |
Correct |
45 ms |
145244 KB |
Output is correct |
31 |
Correct |
43 ms |
145416 KB |
Output is correct |
32 |
Correct |
44 ms |
145240 KB |
Output is correct |
33 |
Correct |
45 ms |
145240 KB |
Output is correct |
34 |
Correct |
43 ms |
145220 KB |
Output is correct |
35 |
Correct |
45 ms |
145244 KB |
Output is correct |
36 |
Correct |
44 ms |
145236 KB |
Output is correct |
37 |
Correct |
45 ms |
145236 KB |
Output is correct |
38 |
Correct |
42 ms |
145244 KB |
Output is correct |
39 |
Correct |
46 ms |
145424 KB |
Output is correct |
40 |
Correct |
47 ms |
145236 KB |
Output is correct |
41 |
Correct |
71 ms |
145232 KB |
Output is correct |
42 |
Correct |
59 ms |
145224 KB |
Output is correct |
43 |
Correct |
76 ms |
145420 KB |
Output is correct |
44 |
Correct |
57 ms |
145232 KB |
Output is correct |
45 |
Correct |
83 ms |
145348 KB |
Output is correct |
46 |
Correct |
54 ms |
145232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
145232 KB |
Output is correct |
2 |
Correct |
42 ms |
145300 KB |
Output is correct |
3 |
Correct |
42 ms |
145272 KB |
Output is correct |
4 |
Correct |
43 ms |
145404 KB |
Output is correct |
5 |
Correct |
41 ms |
145236 KB |
Output is correct |
6 |
Correct |
40 ms |
145244 KB |
Output is correct |
7 |
Correct |
42 ms |
145344 KB |
Output is correct |
8 |
Correct |
43 ms |
145232 KB |
Output is correct |
9 |
Correct |
41 ms |
145352 KB |
Output is correct |
10 |
Correct |
52 ms |
145236 KB |
Output is correct |
11 |
Correct |
42 ms |
145236 KB |
Output is correct |
12 |
Correct |
42 ms |
145240 KB |
Output is correct |
13 |
Correct |
42 ms |
145244 KB |
Output is correct |
14 |
Correct |
42 ms |
145232 KB |
Output is correct |
15 |
Correct |
41 ms |
145236 KB |
Output is correct |
16 |
Correct |
42 ms |
145212 KB |
Output is correct |
17 |
Correct |
40 ms |
145244 KB |
Output is correct |
18 |
Correct |
41 ms |
145232 KB |
Output is correct |
19 |
Correct |
41 ms |
145244 KB |
Output is correct |
20 |
Correct |
41 ms |
145264 KB |
Output is correct |
21 |
Correct |
42 ms |
145240 KB |
Output is correct |
22 |
Correct |
41 ms |
145232 KB |
Output is correct |
23 |
Correct |
41 ms |
145232 KB |
Output is correct |
24 |
Correct |
44 ms |
145356 KB |
Output is correct |
25 |
Correct |
52 ms |
145232 KB |
Output is correct |
26 |
Correct |
43 ms |
145236 KB |
Output is correct |
27 |
Correct |
42 ms |
145232 KB |
Output is correct |
28 |
Correct |
42 ms |
145232 KB |
Output is correct |
29 |
Correct |
43 ms |
145236 KB |
Output is correct |
30 |
Correct |
41 ms |
145244 KB |
Output is correct |
31 |
Correct |
41 ms |
145408 KB |
Output is correct |
32 |
Correct |
42 ms |
145232 KB |
Output is correct |
33 |
Correct |
41 ms |
145244 KB |
Output is correct |
34 |
Correct |
42 ms |
145308 KB |
Output is correct |
35 |
Correct |
43 ms |
145368 KB |
Output is correct |
36 |
Correct |
65 ms |
145180 KB |
Output is correct |
37 |
Correct |
52 ms |
145256 KB |
Output is correct |
38 |
Correct |
46 ms |
145236 KB |
Output is correct |
39 |
Correct |
58 ms |
145232 KB |
Output is correct |
40 |
Correct |
55 ms |
145232 KB |
Output is correct |
41 |
Correct |
57 ms |
145228 KB |
Output is correct |
42 |
Correct |
57 ms |
145416 KB |
Output is correct |
43 |
Correct |
45 ms |
145268 KB |
Output is correct |
44 |
Correct |
42 ms |
145284 KB |
Output is correct |
45 |
Correct |
44 ms |
145244 KB |
Output is correct |
46 |
Correct |
46 ms |
145236 KB |
Output is correct |
47 |
Correct |
45 ms |
145312 KB |
Output is correct |
48 |
Correct |
45 ms |
145244 KB |
Output is correct |
49 |
Correct |
43 ms |
145416 KB |
Output is correct |
50 |
Correct |
44 ms |
145240 KB |
Output is correct |
51 |
Correct |
45 ms |
145240 KB |
Output is correct |
52 |
Correct |
43 ms |
145220 KB |
Output is correct |
53 |
Correct |
45 ms |
145244 KB |
Output is correct |
54 |
Correct |
44 ms |
145236 KB |
Output is correct |
55 |
Correct |
45 ms |
145236 KB |
Output is correct |
56 |
Correct |
42 ms |
145244 KB |
Output is correct |
57 |
Correct |
46 ms |
145424 KB |
Output is correct |
58 |
Correct |
47 ms |
145236 KB |
Output is correct |
59 |
Correct |
71 ms |
145232 KB |
Output is correct |
60 |
Correct |
59 ms |
145224 KB |
Output is correct |
61 |
Correct |
76 ms |
145420 KB |
Output is correct |
62 |
Correct |
57 ms |
145232 KB |
Output is correct |
63 |
Correct |
83 ms |
145348 KB |
Output is correct |
64 |
Correct |
54 ms |
145232 KB |
Output is correct |
65 |
Correct |
65 ms |
145280 KB |
Output is correct |
66 |
Correct |
62 ms |
145244 KB |
Output is correct |
67 |
Correct |
60 ms |
145324 KB |
Output is correct |
68 |
Correct |
57 ms |
145244 KB |
Output is correct |
69 |
Correct |
63 ms |
145232 KB |
Output is correct |
70 |
Correct |
61 ms |
145232 KB |
Output is correct |
71 |
Correct |
80 ms |
145420 KB |
Output is correct |
72 |
Correct |
63 ms |
145232 KB |
Output is correct |
73 |
Correct |
75 ms |
145284 KB |
Output is correct |
74 |
Correct |
59 ms |
145232 KB |
Output is correct |
75 |
Correct |
61 ms |
145232 KB |
Output is correct |
76 |
Correct |
71 ms |
145236 KB |
Output is correct |
77 |
Correct |
66 ms |
145404 KB |
Output is correct |
78 |
Correct |
68 ms |
145232 KB |
Output is correct |
79 |
Correct |
74 ms |
145236 KB |
Output is correct |
80 |
Correct |
72 ms |
145172 KB |
Output is correct |
81 |
Correct |
62 ms |
145424 KB |
Output is correct |
82 |
Correct |
67 ms |
145232 KB |
Output is correct |
83 |
Correct |
72 ms |
145180 KB |
Output is correct |
84 |
Correct |
71 ms |
145208 KB |
Output is correct |
85 |
Correct |
62 ms |
145200 KB |
Output is correct |
86 |
Correct |
65 ms |
145344 KB |
Output is correct |
87 |
Correct |
60 ms |
145224 KB |
Output is correct |
88 |
Correct |
69 ms |
145232 KB |
Output is correct |
89 |
Correct |
67 ms |
145236 KB |
Output is correct |
90 |
Correct |
57 ms |
145400 KB |
Output is correct |
91 |
Correct |
67 ms |
145428 KB |
Output is correct |
92 |
Correct |
81 ms |
145428 KB |
Output is correct |
93 |
Correct |
62 ms |
145292 KB |
Output is correct |