#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
const int N = 2e2 + 5;
long long dp [N][N][N][2];
int pos [N];
int lim [N];
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
int n, tamanho, mx = 0;
cin >> n >> tamanho;
n += 2;
pos[0] = pos[n - 1] = 0;
lim[0] = lim[n - 1] = 1e9;
for (int i = 1; i < n - 1; i++) cin >> pos[i];
for (int i = 1; i < n - 1; i++) cin >> lim[i];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int x = 0; x < N; x++) {
dp[i][j][x][0] = dp[i][j][x][1] = 1e16;
}
}
}
dp[0][n - 1][0][0] = dp[0][n - 1][0][1] = 0;
for (int L = 0; L < n; L++) {
for (int R = n - 1; R >= 0; R--) {
for (int Q = 0; Q <= n; Q++) {
if (dp[L][R][Q][0] < 1e15 || dp[L][R][Q][1] < 1e15) mx = max (mx, Q);
if (L + 1 < n && L + 1 < R) {
// ESQ -> ESQ
long long tempo = dp[L][R][Q][0] + pos[L + 1] - pos[L];
int QTS = Q + (tempo <= lim[L + 1]);
dp[L + 1][R][QTS][0] = min (dp[L + 1][R][QTS][0], tempo);
// DIR -> ESQ
tempo = dp[L][R][Q][1] + tamanho - pos[R] + pos[L + 1];
QTS = Q + (tempo <= lim[L + 1]);
dp[L + 1][R][QTS][0] = min (dp[L + 1][R][QTS][0], tempo);
}
if (R - 1 >= 0 && R - 1 > L) {
// DIR -> DIR
long long tempo = dp[L][R][Q][1] + abs (pos[R] - pos[R - 1]);
int QTS = Q + (tempo <= lim[R - 1]);
dp[L][R - 1][QTS][1] = min (dp[L][R - 1][QTS][1], tempo);
// ESQ -> DIR
tempo = dp[L][R][Q][0] + pos[L] + tamanho - pos[R - 1];
QTS = Q + (tempo <= lim[R - 1]);
dp[L][R - 1][QTS][1] = min (dp[L][R - 1][QTS][1], tempo);
}
}
}
}
cout << mx << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
135160 KB |
Output is correct |
2 |
Correct |
66 ms |
135160 KB |
Output is correct |
3 |
Correct |
65 ms |
135148 KB |
Output is correct |
4 |
Correct |
63 ms |
135288 KB |
Output is correct |
5 |
Correct |
65 ms |
135296 KB |
Output is correct |
6 |
Correct |
64 ms |
135160 KB |
Output is correct |
7 |
Correct |
67 ms |
135160 KB |
Output is correct |
8 |
Correct |
66 ms |
135160 KB |
Output is correct |
9 |
Correct |
65 ms |
135160 KB |
Output is correct |
10 |
Correct |
64 ms |
135264 KB |
Output is correct |
11 |
Correct |
65 ms |
135160 KB |
Output is correct |
12 |
Correct |
64 ms |
135288 KB |
Output is correct |
13 |
Correct |
64 ms |
135160 KB |
Output is correct |
14 |
Correct |
63 ms |
135164 KB |
Output is correct |
15 |
Correct |
64 ms |
135160 KB |
Output is correct |
16 |
Correct |
67 ms |
135288 KB |
Output is correct |
17 |
Correct |
64 ms |
135288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
135160 KB |
Output is correct |
2 |
Correct |
66 ms |
135160 KB |
Output is correct |
3 |
Correct |
65 ms |
135148 KB |
Output is correct |
4 |
Correct |
63 ms |
135288 KB |
Output is correct |
5 |
Correct |
65 ms |
135296 KB |
Output is correct |
6 |
Correct |
64 ms |
135160 KB |
Output is correct |
7 |
Correct |
67 ms |
135160 KB |
Output is correct |
8 |
Correct |
66 ms |
135160 KB |
Output is correct |
9 |
Correct |
65 ms |
135160 KB |
Output is correct |
10 |
Correct |
64 ms |
135264 KB |
Output is correct |
11 |
Correct |
65 ms |
135160 KB |
Output is correct |
12 |
Correct |
64 ms |
135288 KB |
Output is correct |
13 |
Correct |
64 ms |
135160 KB |
Output is correct |
14 |
Correct |
63 ms |
135164 KB |
Output is correct |
15 |
Correct |
64 ms |
135160 KB |
Output is correct |
16 |
Correct |
67 ms |
135288 KB |
Output is correct |
17 |
Correct |
64 ms |
135288 KB |
Output is correct |
18 |
Correct |
64 ms |
135164 KB |
Output is correct |
19 |
Correct |
64 ms |
135160 KB |
Output is correct |
20 |
Correct |
63 ms |
135160 KB |
Output is correct |
21 |
Correct |
65 ms |
135288 KB |
Output is correct |
22 |
Correct |
65 ms |
135160 KB |
Output is correct |
23 |
Correct |
64 ms |
135160 KB |
Output is correct |
24 |
Correct |
65 ms |
135160 KB |
Output is correct |
25 |
Correct |
66 ms |
135160 KB |
Output is correct |
26 |
Correct |
65 ms |
135160 KB |
Output is correct |
27 |
Correct |
65 ms |
135160 KB |
Output is correct |
28 |
Correct |
65 ms |
135160 KB |
Output is correct |
29 |
Correct |
67 ms |
135160 KB |
Output is correct |
30 |
Correct |
65 ms |
135160 KB |
Output is correct |
31 |
Correct |
64 ms |
135160 KB |
Output is correct |
32 |
Correct |
65 ms |
135164 KB |
Output is correct |
33 |
Correct |
66 ms |
135160 KB |
Output is correct |
34 |
Correct |
65 ms |
135160 KB |
Output is correct |
35 |
Correct |
66 ms |
135160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
135160 KB |
Output is correct |
2 |
Correct |
66 ms |
135160 KB |
Output is correct |
3 |
Correct |
65 ms |
135148 KB |
Output is correct |
4 |
Correct |
63 ms |
135288 KB |
Output is correct |
5 |
Correct |
65 ms |
135296 KB |
Output is correct |
6 |
Correct |
64 ms |
135160 KB |
Output is correct |
7 |
Correct |
67 ms |
135160 KB |
Output is correct |
8 |
Correct |
66 ms |
135160 KB |
Output is correct |
9 |
Correct |
65 ms |
135160 KB |
Output is correct |
10 |
Correct |
64 ms |
135264 KB |
Output is correct |
11 |
Correct |
65 ms |
135160 KB |
Output is correct |
12 |
Correct |
64 ms |
135288 KB |
Output is correct |
13 |
Correct |
64 ms |
135160 KB |
Output is correct |
14 |
Correct |
63 ms |
135164 KB |
Output is correct |
15 |
Correct |
64 ms |
135160 KB |
Output is correct |
16 |
Correct |
67 ms |
135288 KB |
Output is correct |
17 |
Correct |
64 ms |
135288 KB |
Output is correct |
18 |
Correct |
166 ms |
135288 KB |
Output is correct |
19 |
Correct |
119 ms |
135160 KB |
Output is correct |
20 |
Correct |
86 ms |
135160 KB |
Output is correct |
21 |
Correct |
112 ms |
135288 KB |
Output is correct |
22 |
Correct |
135 ms |
135160 KB |
Output is correct |
23 |
Correct |
82 ms |
135160 KB |
Output is correct |
24 |
Correct |
76 ms |
135212 KB |
Output is correct |
25 |
Correct |
80 ms |
135160 KB |
Output is correct |
26 |
Correct |
70 ms |
135160 KB |
Output is correct |
27 |
Correct |
83 ms |
135160 KB |
Output is correct |
28 |
Correct |
78 ms |
135160 KB |
Output is correct |
29 |
Correct |
82 ms |
135288 KB |
Output is correct |
30 |
Correct |
78 ms |
135160 KB |
Output is correct |
31 |
Correct |
84 ms |
135160 KB |
Output is correct |
32 |
Correct |
72 ms |
135160 KB |
Output is correct |
33 |
Correct |
82 ms |
135160 KB |
Output is correct |
34 |
Correct |
71 ms |
135160 KB |
Output is correct |
35 |
Correct |
85 ms |
135288 KB |
Output is correct |
36 |
Correct |
73 ms |
135160 KB |
Output is correct |
37 |
Correct |
85 ms |
135288 KB |
Output is correct |
38 |
Correct |
74 ms |
135160 KB |
Output is correct |
39 |
Correct |
86 ms |
135416 KB |
Output is correct |
40 |
Correct |
74 ms |
135160 KB |
Output is correct |
41 |
Correct |
215 ms |
135288 KB |
Output is correct |
42 |
Correct |
149 ms |
135160 KB |
Output is correct |
43 |
Correct |
214 ms |
135288 KB |
Output is correct |
44 |
Correct |
147 ms |
135160 KB |
Output is correct |
45 |
Correct |
207 ms |
135160 KB |
Output is correct |
46 |
Correct |
148 ms |
135288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
135160 KB |
Output is correct |
2 |
Correct |
66 ms |
135160 KB |
Output is correct |
3 |
Correct |
65 ms |
135148 KB |
Output is correct |
4 |
Correct |
63 ms |
135288 KB |
Output is correct |
5 |
Correct |
65 ms |
135296 KB |
Output is correct |
6 |
Correct |
64 ms |
135160 KB |
Output is correct |
7 |
Correct |
67 ms |
135160 KB |
Output is correct |
8 |
Correct |
66 ms |
135160 KB |
Output is correct |
9 |
Correct |
65 ms |
135160 KB |
Output is correct |
10 |
Correct |
64 ms |
135264 KB |
Output is correct |
11 |
Correct |
65 ms |
135160 KB |
Output is correct |
12 |
Correct |
64 ms |
135288 KB |
Output is correct |
13 |
Correct |
64 ms |
135160 KB |
Output is correct |
14 |
Correct |
63 ms |
135164 KB |
Output is correct |
15 |
Correct |
64 ms |
135160 KB |
Output is correct |
16 |
Correct |
67 ms |
135288 KB |
Output is correct |
17 |
Correct |
64 ms |
135288 KB |
Output is correct |
18 |
Correct |
64 ms |
135164 KB |
Output is correct |
19 |
Correct |
64 ms |
135160 KB |
Output is correct |
20 |
Correct |
63 ms |
135160 KB |
Output is correct |
21 |
Correct |
65 ms |
135288 KB |
Output is correct |
22 |
Correct |
65 ms |
135160 KB |
Output is correct |
23 |
Correct |
64 ms |
135160 KB |
Output is correct |
24 |
Correct |
65 ms |
135160 KB |
Output is correct |
25 |
Correct |
66 ms |
135160 KB |
Output is correct |
26 |
Correct |
65 ms |
135160 KB |
Output is correct |
27 |
Correct |
65 ms |
135160 KB |
Output is correct |
28 |
Correct |
65 ms |
135160 KB |
Output is correct |
29 |
Correct |
67 ms |
135160 KB |
Output is correct |
30 |
Correct |
65 ms |
135160 KB |
Output is correct |
31 |
Correct |
64 ms |
135160 KB |
Output is correct |
32 |
Correct |
65 ms |
135164 KB |
Output is correct |
33 |
Correct |
66 ms |
135160 KB |
Output is correct |
34 |
Correct |
65 ms |
135160 KB |
Output is correct |
35 |
Correct |
66 ms |
135160 KB |
Output is correct |
36 |
Correct |
166 ms |
135288 KB |
Output is correct |
37 |
Correct |
119 ms |
135160 KB |
Output is correct |
38 |
Correct |
86 ms |
135160 KB |
Output is correct |
39 |
Correct |
112 ms |
135288 KB |
Output is correct |
40 |
Correct |
135 ms |
135160 KB |
Output is correct |
41 |
Correct |
82 ms |
135160 KB |
Output is correct |
42 |
Correct |
76 ms |
135212 KB |
Output is correct |
43 |
Correct |
80 ms |
135160 KB |
Output is correct |
44 |
Correct |
70 ms |
135160 KB |
Output is correct |
45 |
Correct |
83 ms |
135160 KB |
Output is correct |
46 |
Correct |
78 ms |
135160 KB |
Output is correct |
47 |
Correct |
82 ms |
135288 KB |
Output is correct |
48 |
Correct |
78 ms |
135160 KB |
Output is correct |
49 |
Correct |
84 ms |
135160 KB |
Output is correct |
50 |
Correct |
72 ms |
135160 KB |
Output is correct |
51 |
Correct |
82 ms |
135160 KB |
Output is correct |
52 |
Correct |
71 ms |
135160 KB |
Output is correct |
53 |
Correct |
85 ms |
135288 KB |
Output is correct |
54 |
Correct |
73 ms |
135160 KB |
Output is correct |
55 |
Correct |
85 ms |
135288 KB |
Output is correct |
56 |
Correct |
74 ms |
135160 KB |
Output is correct |
57 |
Correct |
86 ms |
135416 KB |
Output is correct |
58 |
Correct |
74 ms |
135160 KB |
Output is correct |
59 |
Correct |
215 ms |
135288 KB |
Output is correct |
60 |
Correct |
149 ms |
135160 KB |
Output is correct |
61 |
Correct |
214 ms |
135288 KB |
Output is correct |
62 |
Correct |
147 ms |
135160 KB |
Output is correct |
63 |
Correct |
207 ms |
135160 KB |
Output is correct |
64 |
Correct |
148 ms |
135288 KB |
Output is correct |
65 |
Correct |
182 ms |
135160 KB |
Output is correct |
66 |
Correct |
177 ms |
135288 KB |
Output is correct |
67 |
Correct |
180 ms |
135288 KB |
Output is correct |
68 |
Correct |
159 ms |
135260 KB |
Output is correct |
69 |
Correct |
188 ms |
135164 KB |
Output is correct |
70 |
Correct |
183 ms |
135160 KB |
Output is correct |
71 |
Correct |
191 ms |
135288 KB |
Output is correct |
72 |
Correct |
180 ms |
135288 KB |
Output is correct |
73 |
Correct |
175 ms |
135292 KB |
Output is correct |
74 |
Correct |
158 ms |
135288 KB |
Output is correct |
75 |
Correct |
179 ms |
135160 KB |
Output is correct |
76 |
Correct |
196 ms |
135160 KB |
Output is correct |
77 |
Correct |
204 ms |
135188 KB |
Output is correct |
78 |
Correct |
164 ms |
135308 KB |
Output is correct |
79 |
Correct |
167 ms |
135160 KB |
Output is correct |
80 |
Correct |
202 ms |
135160 KB |
Output is correct |
81 |
Correct |
167 ms |
135160 KB |
Output is correct |
82 |
Correct |
174 ms |
135160 KB |
Output is correct |
83 |
Correct |
204 ms |
135524 KB |
Output is correct |
84 |
Correct |
183 ms |
135160 KB |
Output is correct |
85 |
Correct |
196 ms |
135164 KB |
Output is correct |
86 |
Correct |
194 ms |
135236 KB |
Output is correct |
87 |
Correct |
178 ms |
135288 KB |
Output is correct |
88 |
Correct |
213 ms |
135288 KB |
Output is correct |
89 |
Correct |
214 ms |
135160 KB |
Output is correct |
90 |
Correct |
179 ms |
135164 KB |
Output is correct |
91 |
Correct |
219 ms |
135288 KB |
Output is correct |
92 |
Correct |
213 ms |
135288 KB |
Output is correct |
93 |
Correct |
212 ms |
135160 KB |
Output is correct |