#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int MXN = 205;
int n, L, a[MXN], t[MXN], ans = 0;
int dp[MXN][MXN][MXN][2];
int dis(int l, int r, bool o) {
if (l > r) swap(l, r);
if (o) return L - (a[r] - a[l]);
return a[r] - a[l];
}
void CALCDP(int l, int r) {
// cout << l << ' ' << r << endl;
// dp[l][r][n - (r - l) + 1][0] = INT_MAX;
// dp[l][r][n - (r - l) + 1][1] = INT_MAX;
// dp[l][r][n - (r - l) + 2][0] = INT_MAX;
// dp[l][r][n - (r - l) + 2][1] = INT_MAX;
for (int s = n - (r - l) + 1; s > 0; s--) {
if (r <= n) {
dp[l][r][s][0] = max(dp[l][r][s][0], dp[l][r][s + 1][0]);
if (dp[l][r + 1][s - 1][0] + dis(r, r + 1, false) <= t[r]) dp[l][r][s][0] = min(dp[l][r][s][0], dp[l][r + 1][s - 1][0] + dis(r, r + 1, false));
if (dp[l][r + 1][s - 1][1] + dis(l, r, true) <= t[r]) dp[l][r][s][0] = min(dp[l][r][s][0], dp[l][r + 1][s - 1][1] + dis(l, r, true));
dp[l][r][s][0] = min(dp[l][r][s][0], dp[l][r + 1][s][0] + dis(r, r + 1, false));
dp[l][r][s][0] = min(dp[l][r][s][0], dp[l][r + 1][s][1] + dis(l, r, true));
if (dp[l][r][s][0] < INT_MAX) {
ans = max(ans, s);
// cout << l << ' ' << r << ' ' << 0 << ' ' << s << endl;
}
}
if (l) {
dp[l][r][s][1] = max(dp[l][r][s][1], dp[l][r][s + 1][1]);
if (dp[l - 1][r][s - 1][0] + dis(l, r, true) <= t[l]) dp[l][r][s][1] = min(dp[l][r][s][1], dp[l - 1][r][s - 1][0] + dis(l, r, true));
if (dp[l - 1][r][s - 1][1] + dis(l - 1, l, false) <= t[l]) dp[l][r][s][1] = min(dp[l][r][s][1], dp[l - 1][r][s - 1][1] + dis(l - 1, l, false));
dp[l][r][s][1] = min(dp[l][r][s][1], dp[l - 1][r][s][0] + dis(l, r, true));
dp[l][r][s][1] = min(dp[l][r][s][1], dp[l - 1][r][s][1] + dis(l - 1, l, false));
if (dp[l][r][s][1] < INT_MAX) {
ans = max(ans, s);
// cout << l << ' ' << r << ' ' << 1 << ' ' << s << endl;
}
}
}
if (r <= n) dp[l][r][0][0] = a[l] + dis(l, r, true);
if (l) dp[l][r][0][1] = L - a[r] + dis(l, r, true);
}
int solve() {
fill(&dp[0][0][0][0], &dp[0][0][0][0] + MXN * MXN * MXN * 2, INT_MAX);
cin >> n >> L;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> t[i];
a[0] = 0;
a[n + 1] = L;
t[0] = -1;
t[n + 1] = -1;
dp[0][n + 1][0][0] = 0;
dp[0][n + 1][0][1] = 0;
for (int i = 1; i < n; i++) {
dp[0][n + 1][i][0] = INT_MAX;
dp[0][n + 1][i][1] = INT_MAX;
}
for (int dif = n; dif > 0; dif--) {
for (int l = 0; l + dif <= n + 1; l++) {
int r = l + dif;
CALCDP(l, r);
}
}
// cout << dp[1][5][3][1] << endl;
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << solve() << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
135076 KB |
Output is correct |
2 |
Correct |
53 ms |
135064 KB |
Output is correct |
3 |
Correct |
54 ms |
135072 KB |
Output is correct |
4 |
Correct |
52 ms |
135148 KB |
Output is correct |
5 |
Correct |
55 ms |
135116 KB |
Output is correct |
6 |
Correct |
53 ms |
135060 KB |
Output is correct |
7 |
Correct |
54 ms |
135052 KB |
Output is correct |
8 |
Correct |
54 ms |
135060 KB |
Output is correct |
9 |
Correct |
56 ms |
135116 KB |
Output is correct |
10 |
Correct |
53 ms |
135144 KB |
Output is correct |
11 |
Correct |
54 ms |
135116 KB |
Output is correct |
12 |
Correct |
56 ms |
135184 KB |
Output is correct |
13 |
Correct |
54 ms |
135108 KB |
Output is correct |
14 |
Correct |
55 ms |
135164 KB |
Output is correct |
15 |
Correct |
54 ms |
135052 KB |
Output is correct |
16 |
Correct |
56 ms |
135124 KB |
Output is correct |
17 |
Correct |
54 ms |
135116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
135076 KB |
Output is correct |
2 |
Correct |
53 ms |
135064 KB |
Output is correct |
3 |
Correct |
54 ms |
135072 KB |
Output is correct |
4 |
Correct |
52 ms |
135148 KB |
Output is correct |
5 |
Correct |
55 ms |
135116 KB |
Output is correct |
6 |
Correct |
53 ms |
135060 KB |
Output is correct |
7 |
Correct |
54 ms |
135052 KB |
Output is correct |
8 |
Correct |
54 ms |
135060 KB |
Output is correct |
9 |
Correct |
56 ms |
135116 KB |
Output is correct |
10 |
Correct |
53 ms |
135144 KB |
Output is correct |
11 |
Correct |
54 ms |
135116 KB |
Output is correct |
12 |
Correct |
56 ms |
135184 KB |
Output is correct |
13 |
Correct |
54 ms |
135108 KB |
Output is correct |
14 |
Correct |
55 ms |
135164 KB |
Output is correct |
15 |
Correct |
54 ms |
135052 KB |
Output is correct |
16 |
Correct |
56 ms |
135124 KB |
Output is correct |
17 |
Correct |
54 ms |
135116 KB |
Output is correct |
18 |
Correct |
54 ms |
135236 KB |
Output is correct |
19 |
Correct |
57 ms |
135132 KB |
Output is correct |
20 |
Correct |
54 ms |
135152 KB |
Output is correct |
21 |
Correct |
57 ms |
135116 KB |
Output is correct |
22 |
Correct |
55 ms |
135148 KB |
Output is correct |
23 |
Correct |
59 ms |
135168 KB |
Output is correct |
24 |
Correct |
53 ms |
135156 KB |
Output is correct |
25 |
Correct |
56 ms |
135092 KB |
Output is correct |
26 |
Correct |
55 ms |
135104 KB |
Output is correct |
27 |
Correct |
54 ms |
135076 KB |
Output is correct |
28 |
Correct |
56 ms |
135116 KB |
Output is correct |
29 |
Correct |
56 ms |
135084 KB |
Output is correct |
30 |
Correct |
55 ms |
135128 KB |
Output is correct |
31 |
Correct |
55 ms |
135092 KB |
Output is correct |
32 |
Correct |
55 ms |
135140 KB |
Output is correct |
33 |
Correct |
55 ms |
135152 KB |
Output is correct |
34 |
Correct |
57 ms |
135116 KB |
Output is correct |
35 |
Correct |
55 ms |
135112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
135076 KB |
Output is correct |
2 |
Correct |
53 ms |
135064 KB |
Output is correct |
3 |
Correct |
54 ms |
135072 KB |
Output is correct |
4 |
Correct |
52 ms |
135148 KB |
Output is correct |
5 |
Correct |
55 ms |
135116 KB |
Output is correct |
6 |
Correct |
53 ms |
135060 KB |
Output is correct |
7 |
Correct |
54 ms |
135052 KB |
Output is correct |
8 |
Correct |
54 ms |
135060 KB |
Output is correct |
9 |
Correct |
56 ms |
135116 KB |
Output is correct |
10 |
Correct |
53 ms |
135144 KB |
Output is correct |
11 |
Correct |
54 ms |
135116 KB |
Output is correct |
12 |
Correct |
56 ms |
135184 KB |
Output is correct |
13 |
Correct |
54 ms |
135108 KB |
Output is correct |
14 |
Correct |
55 ms |
135164 KB |
Output is correct |
15 |
Correct |
54 ms |
135052 KB |
Output is correct |
16 |
Correct |
56 ms |
135124 KB |
Output is correct |
17 |
Correct |
54 ms |
135116 KB |
Output is correct |
18 |
Correct |
69 ms |
135112 KB |
Output is correct |
19 |
Correct |
62 ms |
135068 KB |
Output is correct |
20 |
Correct |
58 ms |
135052 KB |
Output is correct |
21 |
Correct |
63 ms |
135120 KB |
Output is correct |
22 |
Correct |
65 ms |
135120 KB |
Output is correct |
23 |
Correct |
59 ms |
135152 KB |
Output is correct |
24 |
Correct |
55 ms |
135164 KB |
Output is correct |
25 |
Correct |
62 ms |
135268 KB |
Output is correct |
26 |
Correct |
54 ms |
135096 KB |
Output is correct |
27 |
Correct |
58 ms |
135152 KB |
Output is correct |
28 |
Correct |
54 ms |
135164 KB |
Output is correct |
29 |
Correct |
55 ms |
135244 KB |
Output is correct |
30 |
Correct |
56 ms |
135060 KB |
Output is correct |
31 |
Correct |
59 ms |
135132 KB |
Output is correct |
32 |
Correct |
56 ms |
135120 KB |
Output is correct |
33 |
Correct |
62 ms |
135088 KB |
Output is correct |
34 |
Correct |
54 ms |
135108 KB |
Output is correct |
35 |
Correct |
57 ms |
135156 KB |
Output is correct |
36 |
Correct |
56 ms |
135128 KB |
Output is correct |
37 |
Correct |
58 ms |
135092 KB |
Output is correct |
38 |
Correct |
56 ms |
135120 KB |
Output is correct |
39 |
Correct |
56 ms |
135104 KB |
Output is correct |
40 |
Correct |
56 ms |
135172 KB |
Output is correct |
41 |
Correct |
73 ms |
135116 KB |
Output is correct |
42 |
Correct |
67 ms |
135092 KB |
Output is correct |
43 |
Correct |
76 ms |
135176 KB |
Output is correct |
44 |
Correct |
70 ms |
135112 KB |
Output is correct |
45 |
Correct |
78 ms |
135164 KB |
Output is correct |
46 |
Correct |
67 ms |
135128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
135076 KB |
Output is correct |
2 |
Correct |
53 ms |
135064 KB |
Output is correct |
3 |
Correct |
54 ms |
135072 KB |
Output is correct |
4 |
Correct |
52 ms |
135148 KB |
Output is correct |
5 |
Correct |
55 ms |
135116 KB |
Output is correct |
6 |
Correct |
53 ms |
135060 KB |
Output is correct |
7 |
Correct |
54 ms |
135052 KB |
Output is correct |
8 |
Correct |
54 ms |
135060 KB |
Output is correct |
9 |
Correct |
56 ms |
135116 KB |
Output is correct |
10 |
Correct |
53 ms |
135144 KB |
Output is correct |
11 |
Correct |
54 ms |
135116 KB |
Output is correct |
12 |
Correct |
56 ms |
135184 KB |
Output is correct |
13 |
Correct |
54 ms |
135108 KB |
Output is correct |
14 |
Correct |
55 ms |
135164 KB |
Output is correct |
15 |
Correct |
54 ms |
135052 KB |
Output is correct |
16 |
Correct |
56 ms |
135124 KB |
Output is correct |
17 |
Correct |
54 ms |
135116 KB |
Output is correct |
18 |
Correct |
54 ms |
135236 KB |
Output is correct |
19 |
Correct |
57 ms |
135132 KB |
Output is correct |
20 |
Correct |
54 ms |
135152 KB |
Output is correct |
21 |
Correct |
57 ms |
135116 KB |
Output is correct |
22 |
Correct |
55 ms |
135148 KB |
Output is correct |
23 |
Correct |
59 ms |
135168 KB |
Output is correct |
24 |
Correct |
53 ms |
135156 KB |
Output is correct |
25 |
Correct |
56 ms |
135092 KB |
Output is correct |
26 |
Correct |
55 ms |
135104 KB |
Output is correct |
27 |
Correct |
54 ms |
135076 KB |
Output is correct |
28 |
Correct |
56 ms |
135116 KB |
Output is correct |
29 |
Correct |
56 ms |
135084 KB |
Output is correct |
30 |
Correct |
55 ms |
135128 KB |
Output is correct |
31 |
Correct |
55 ms |
135092 KB |
Output is correct |
32 |
Correct |
55 ms |
135140 KB |
Output is correct |
33 |
Correct |
55 ms |
135152 KB |
Output is correct |
34 |
Correct |
57 ms |
135116 KB |
Output is correct |
35 |
Correct |
55 ms |
135112 KB |
Output is correct |
36 |
Correct |
69 ms |
135112 KB |
Output is correct |
37 |
Correct |
62 ms |
135068 KB |
Output is correct |
38 |
Correct |
58 ms |
135052 KB |
Output is correct |
39 |
Correct |
63 ms |
135120 KB |
Output is correct |
40 |
Correct |
65 ms |
135120 KB |
Output is correct |
41 |
Correct |
59 ms |
135152 KB |
Output is correct |
42 |
Correct |
55 ms |
135164 KB |
Output is correct |
43 |
Correct |
62 ms |
135268 KB |
Output is correct |
44 |
Correct |
54 ms |
135096 KB |
Output is correct |
45 |
Correct |
58 ms |
135152 KB |
Output is correct |
46 |
Correct |
54 ms |
135164 KB |
Output is correct |
47 |
Correct |
55 ms |
135244 KB |
Output is correct |
48 |
Correct |
56 ms |
135060 KB |
Output is correct |
49 |
Correct |
59 ms |
135132 KB |
Output is correct |
50 |
Correct |
56 ms |
135120 KB |
Output is correct |
51 |
Correct |
62 ms |
135088 KB |
Output is correct |
52 |
Correct |
54 ms |
135108 KB |
Output is correct |
53 |
Correct |
57 ms |
135156 KB |
Output is correct |
54 |
Correct |
56 ms |
135128 KB |
Output is correct |
55 |
Correct |
58 ms |
135092 KB |
Output is correct |
56 |
Correct |
56 ms |
135120 KB |
Output is correct |
57 |
Correct |
56 ms |
135104 KB |
Output is correct |
58 |
Correct |
56 ms |
135172 KB |
Output is correct |
59 |
Correct |
73 ms |
135116 KB |
Output is correct |
60 |
Correct |
67 ms |
135092 KB |
Output is correct |
61 |
Correct |
76 ms |
135176 KB |
Output is correct |
62 |
Correct |
70 ms |
135112 KB |
Output is correct |
63 |
Correct |
78 ms |
135164 KB |
Output is correct |
64 |
Correct |
67 ms |
135128 KB |
Output is correct |
65 |
Correct |
73 ms |
135080 KB |
Output is correct |
66 |
Correct |
78 ms |
135148 KB |
Output is correct |
67 |
Correct |
67 ms |
135108 KB |
Output is correct |
68 |
Correct |
65 ms |
135068 KB |
Output is correct |
69 |
Correct |
71 ms |
135088 KB |
Output is correct |
70 |
Correct |
73 ms |
135124 KB |
Output is correct |
71 |
Correct |
70 ms |
135104 KB |
Output is correct |
72 |
Correct |
72 ms |
135076 KB |
Output is correct |
73 |
Correct |
69 ms |
135088 KB |
Output is correct |
74 |
Correct |
68 ms |
135056 KB |
Output is correct |
75 |
Correct |
72 ms |
135128 KB |
Output is correct |
76 |
Correct |
74 ms |
135104 KB |
Output is correct |
77 |
Correct |
72 ms |
135168 KB |
Output is correct |
78 |
Correct |
66 ms |
135184 KB |
Output is correct |
79 |
Correct |
73 ms |
135084 KB |
Output is correct |
80 |
Correct |
74 ms |
135096 KB |
Output is correct |
81 |
Correct |
67 ms |
135128 KB |
Output is correct |
82 |
Correct |
69 ms |
135172 KB |
Output is correct |
83 |
Correct |
72 ms |
135172 KB |
Output is correct |
84 |
Correct |
70 ms |
135064 KB |
Output is correct |
85 |
Correct |
73 ms |
135072 KB |
Output is correct |
86 |
Correct |
73 ms |
135112 KB |
Output is correct |
87 |
Correct |
71 ms |
135144 KB |
Output is correct |
88 |
Correct |
75 ms |
135128 KB |
Output is correct |
89 |
Correct |
78 ms |
135152 KB |
Output is correct |
90 |
Correct |
69 ms |
135104 KB |
Output is correct |
91 |
Correct |
78 ms |
135088 KB |
Output is correct |
92 |
Correct |
77 ms |
135180 KB |
Output is correct |
93 |
Correct |
74 ms |
135084 KB |
Output is correct |