#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[201][201][201][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 <= 200; i++) {
for (int j = 0; j <= 200;j++) {
for (int cnt = 0; cnt <= 200; cnt++) {
for (int I = 0; I < 2; I++) dp[i][j][cnt][I] = 1e18;
}
}
}
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) {
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] < 1e18 || dp[left][n + 1 - left][cnt][1] < 1e18) ans = max(ans, cnt);
}
}
cout << ans - 1 << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
127312 KB |
Output is correct |
2 |
Correct |
36 ms |
127416 KB |
Output is correct |
3 |
Correct |
41 ms |
127312 KB |
Output is correct |
4 |
Correct |
39 ms |
127312 KB |
Output is correct |
5 |
Correct |
37 ms |
127568 KB |
Output is correct |
6 |
Correct |
37 ms |
127316 KB |
Output is correct |
7 |
Correct |
35 ms |
127312 KB |
Output is correct |
8 |
Correct |
40 ms |
127316 KB |
Output is correct |
9 |
Correct |
37 ms |
127312 KB |
Output is correct |
10 |
Correct |
35 ms |
127312 KB |
Output is correct |
11 |
Correct |
36 ms |
127312 KB |
Output is correct |
12 |
Correct |
36 ms |
127484 KB |
Output is correct |
13 |
Correct |
37 ms |
127316 KB |
Output is correct |
14 |
Correct |
36 ms |
127380 KB |
Output is correct |
15 |
Correct |
36 ms |
127580 KB |
Output is correct |
16 |
Correct |
37 ms |
127316 KB |
Output is correct |
17 |
Correct |
36 ms |
127316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
127312 KB |
Output is correct |
2 |
Correct |
36 ms |
127416 KB |
Output is correct |
3 |
Correct |
41 ms |
127312 KB |
Output is correct |
4 |
Correct |
39 ms |
127312 KB |
Output is correct |
5 |
Correct |
37 ms |
127568 KB |
Output is correct |
6 |
Correct |
37 ms |
127316 KB |
Output is correct |
7 |
Correct |
35 ms |
127312 KB |
Output is correct |
8 |
Correct |
40 ms |
127316 KB |
Output is correct |
9 |
Correct |
37 ms |
127312 KB |
Output is correct |
10 |
Correct |
35 ms |
127312 KB |
Output is correct |
11 |
Correct |
36 ms |
127312 KB |
Output is correct |
12 |
Correct |
36 ms |
127484 KB |
Output is correct |
13 |
Correct |
37 ms |
127316 KB |
Output is correct |
14 |
Correct |
36 ms |
127380 KB |
Output is correct |
15 |
Correct |
36 ms |
127580 KB |
Output is correct |
16 |
Correct |
37 ms |
127316 KB |
Output is correct |
17 |
Correct |
36 ms |
127316 KB |
Output is correct |
18 |
Correct |
44 ms |
127316 KB |
Output is correct |
19 |
Correct |
37 ms |
127508 KB |
Output is correct |
20 |
Correct |
36 ms |
127316 KB |
Output is correct |
21 |
Correct |
37 ms |
127312 KB |
Output is correct |
22 |
Correct |
36 ms |
127312 KB |
Output is correct |
23 |
Correct |
36 ms |
127568 KB |
Output is correct |
24 |
Correct |
36 ms |
127576 KB |
Output is correct |
25 |
Correct |
36 ms |
127316 KB |
Output is correct |
26 |
Correct |
37 ms |
127320 KB |
Output is correct |
27 |
Correct |
36 ms |
127576 KB |
Output is correct |
28 |
Correct |
36 ms |
127536 KB |
Output is correct |
29 |
Correct |
36 ms |
127576 KB |
Output is correct |
30 |
Correct |
35 ms |
127316 KB |
Output is correct |
31 |
Correct |
36 ms |
127316 KB |
Output is correct |
32 |
Correct |
36 ms |
127564 KB |
Output is correct |
33 |
Correct |
35 ms |
127376 KB |
Output is correct |
34 |
Correct |
42 ms |
127312 KB |
Output is correct |
35 |
Correct |
42 ms |
127312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
127312 KB |
Output is correct |
2 |
Correct |
36 ms |
127416 KB |
Output is correct |
3 |
Correct |
41 ms |
127312 KB |
Output is correct |
4 |
Correct |
39 ms |
127312 KB |
Output is correct |
5 |
Correct |
37 ms |
127568 KB |
Output is correct |
6 |
Correct |
37 ms |
127316 KB |
Output is correct |
7 |
Correct |
35 ms |
127312 KB |
Output is correct |
8 |
Correct |
40 ms |
127316 KB |
Output is correct |
9 |
Correct |
37 ms |
127312 KB |
Output is correct |
10 |
Correct |
35 ms |
127312 KB |
Output is correct |
11 |
Correct |
36 ms |
127312 KB |
Output is correct |
12 |
Correct |
36 ms |
127484 KB |
Output is correct |
13 |
Correct |
37 ms |
127316 KB |
Output is correct |
14 |
Correct |
36 ms |
127380 KB |
Output is correct |
15 |
Correct |
36 ms |
127580 KB |
Output is correct |
16 |
Correct |
37 ms |
127316 KB |
Output is correct |
17 |
Correct |
36 ms |
127316 KB |
Output is correct |
18 |
Correct |
52 ms |
127400 KB |
Output is correct |
19 |
Correct |
45 ms |
127568 KB |
Output is correct |
20 |
Correct |
48 ms |
127488 KB |
Output is correct |
21 |
Correct |
48 ms |
127568 KB |
Output is correct |
22 |
Correct |
45 ms |
127480 KB |
Output is correct |
23 |
Correct |
41 ms |
127364 KB |
Output is correct |
24 |
Correct |
38 ms |
127556 KB |
Output is correct |
25 |
Correct |
40 ms |
127580 KB |
Output is correct |
26 |
Correct |
40 ms |
127316 KB |
Output is correct |
27 |
Correct |
44 ms |
127580 KB |
Output is correct |
28 |
Correct |
38 ms |
127580 KB |
Output is correct |
29 |
Correct |
38 ms |
127316 KB |
Output is correct |
30 |
Correct |
39 ms |
127528 KB |
Output is correct |
31 |
Correct |
39 ms |
127580 KB |
Output is correct |
32 |
Correct |
37 ms |
127436 KB |
Output is correct |
33 |
Correct |
39 ms |
127396 KB |
Output is correct |
34 |
Correct |
37 ms |
127316 KB |
Output is correct |
35 |
Correct |
39 ms |
127312 KB |
Output is correct |
36 |
Correct |
40 ms |
127568 KB |
Output is correct |
37 |
Correct |
39 ms |
127580 KB |
Output is correct |
38 |
Correct |
37 ms |
127316 KB |
Output is correct |
39 |
Correct |
38 ms |
127540 KB |
Output is correct |
40 |
Correct |
38 ms |
127568 KB |
Output is correct |
41 |
Correct |
57 ms |
127568 KB |
Output is correct |
42 |
Correct |
57 ms |
127464 KB |
Output is correct |
43 |
Correct |
59 ms |
127572 KB |
Output is correct |
44 |
Correct |
47 ms |
127572 KB |
Output is correct |
45 |
Correct |
58 ms |
127316 KB |
Output is correct |
46 |
Correct |
47 ms |
127316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
127312 KB |
Output is correct |
2 |
Correct |
36 ms |
127416 KB |
Output is correct |
3 |
Correct |
41 ms |
127312 KB |
Output is correct |
4 |
Correct |
39 ms |
127312 KB |
Output is correct |
5 |
Correct |
37 ms |
127568 KB |
Output is correct |
6 |
Correct |
37 ms |
127316 KB |
Output is correct |
7 |
Correct |
35 ms |
127312 KB |
Output is correct |
8 |
Correct |
40 ms |
127316 KB |
Output is correct |
9 |
Correct |
37 ms |
127312 KB |
Output is correct |
10 |
Correct |
35 ms |
127312 KB |
Output is correct |
11 |
Correct |
36 ms |
127312 KB |
Output is correct |
12 |
Correct |
36 ms |
127484 KB |
Output is correct |
13 |
Correct |
37 ms |
127316 KB |
Output is correct |
14 |
Correct |
36 ms |
127380 KB |
Output is correct |
15 |
Correct |
36 ms |
127580 KB |
Output is correct |
16 |
Correct |
37 ms |
127316 KB |
Output is correct |
17 |
Correct |
36 ms |
127316 KB |
Output is correct |
18 |
Correct |
44 ms |
127316 KB |
Output is correct |
19 |
Correct |
37 ms |
127508 KB |
Output is correct |
20 |
Correct |
36 ms |
127316 KB |
Output is correct |
21 |
Correct |
37 ms |
127312 KB |
Output is correct |
22 |
Correct |
36 ms |
127312 KB |
Output is correct |
23 |
Correct |
36 ms |
127568 KB |
Output is correct |
24 |
Correct |
36 ms |
127576 KB |
Output is correct |
25 |
Correct |
36 ms |
127316 KB |
Output is correct |
26 |
Correct |
37 ms |
127320 KB |
Output is correct |
27 |
Correct |
36 ms |
127576 KB |
Output is correct |
28 |
Correct |
36 ms |
127536 KB |
Output is correct |
29 |
Correct |
36 ms |
127576 KB |
Output is correct |
30 |
Correct |
35 ms |
127316 KB |
Output is correct |
31 |
Correct |
36 ms |
127316 KB |
Output is correct |
32 |
Correct |
36 ms |
127564 KB |
Output is correct |
33 |
Correct |
35 ms |
127376 KB |
Output is correct |
34 |
Correct |
42 ms |
127312 KB |
Output is correct |
35 |
Correct |
42 ms |
127312 KB |
Output is correct |
36 |
Correct |
52 ms |
127400 KB |
Output is correct |
37 |
Correct |
45 ms |
127568 KB |
Output is correct |
38 |
Correct |
48 ms |
127488 KB |
Output is correct |
39 |
Correct |
48 ms |
127568 KB |
Output is correct |
40 |
Correct |
45 ms |
127480 KB |
Output is correct |
41 |
Correct |
41 ms |
127364 KB |
Output is correct |
42 |
Correct |
38 ms |
127556 KB |
Output is correct |
43 |
Correct |
40 ms |
127580 KB |
Output is correct |
44 |
Correct |
40 ms |
127316 KB |
Output is correct |
45 |
Correct |
44 ms |
127580 KB |
Output is correct |
46 |
Correct |
38 ms |
127580 KB |
Output is correct |
47 |
Correct |
38 ms |
127316 KB |
Output is correct |
48 |
Correct |
39 ms |
127528 KB |
Output is correct |
49 |
Correct |
39 ms |
127580 KB |
Output is correct |
50 |
Correct |
37 ms |
127436 KB |
Output is correct |
51 |
Correct |
39 ms |
127396 KB |
Output is correct |
52 |
Correct |
37 ms |
127316 KB |
Output is correct |
53 |
Correct |
39 ms |
127312 KB |
Output is correct |
54 |
Correct |
40 ms |
127568 KB |
Output is correct |
55 |
Correct |
39 ms |
127580 KB |
Output is correct |
56 |
Correct |
37 ms |
127316 KB |
Output is correct |
57 |
Correct |
38 ms |
127540 KB |
Output is correct |
58 |
Correct |
38 ms |
127568 KB |
Output is correct |
59 |
Correct |
57 ms |
127568 KB |
Output is correct |
60 |
Correct |
57 ms |
127464 KB |
Output is correct |
61 |
Correct |
59 ms |
127572 KB |
Output is correct |
62 |
Correct |
47 ms |
127572 KB |
Output is correct |
63 |
Correct |
58 ms |
127316 KB |
Output is correct |
64 |
Correct |
47 ms |
127316 KB |
Output is correct |
65 |
Correct |
58 ms |
127536 KB |
Output is correct |
66 |
Correct |
55 ms |
127500 KB |
Output is correct |
67 |
Correct |
56 ms |
127568 KB |
Output is correct |
68 |
Correct |
49 ms |
127572 KB |
Output is correct |
69 |
Correct |
57 ms |
127576 KB |
Output is correct |
70 |
Correct |
57 ms |
127456 KB |
Output is correct |
71 |
Correct |
52 ms |
127572 KB |
Output is correct |
72 |
Correct |
55 ms |
127572 KB |
Output is correct |
73 |
Correct |
53 ms |
127564 KB |
Output is correct |
74 |
Correct |
55 ms |
127580 KB |
Output is correct |
75 |
Correct |
55 ms |
127572 KB |
Output is correct |
76 |
Correct |
63 ms |
127572 KB |
Output is correct |
77 |
Correct |
56 ms |
127568 KB |
Output is correct |
78 |
Correct |
55 ms |
127500 KB |
Output is correct |
79 |
Correct |
53 ms |
127576 KB |
Output is correct |
80 |
Correct |
57 ms |
127820 KB |
Output is correct |
81 |
Correct |
53 ms |
127484 KB |
Output is correct |
82 |
Correct |
60 ms |
127568 KB |
Output is correct |
83 |
Correct |
60 ms |
127568 KB |
Output is correct |
84 |
Correct |
54 ms |
127568 KB |
Output is correct |
85 |
Correct |
55 ms |
127572 KB |
Output is correct |
86 |
Correct |
56 ms |
127568 KB |
Output is correct |
87 |
Correct |
54 ms |
127472 KB |
Output is correct |
88 |
Correct |
58 ms |
127532 KB |
Output is correct |
89 |
Incorrect |
57 ms |
127568 KB |
Output isn't correct |
90 |
Halted |
0 ms |
0 KB |
- |