#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
int const nmax = 200;
ll const inf = 2000000000;
ll v[5 + 2 * nmax], t[5 + 2 * nmax];
ll dp[5 + 2 * nmax][5 + 2 * nmax][5 + nmax][2];
int n;
ll extract(int x, int y, int val, int h){
if(val < 0)
return inf;
else
return dp[x][y][val][h];
}
ll dist(int x, int y){
return fabs(v[x] - v[y]);
}
void update(ll &number, ll val){
number = min(number, val);
}
int main()
{
int l;
cin >> n >> l;
for(int i = 1;i <= n; i++)
cin >> v[i];
for(int i = 1;i <= n; i++)
cin >> t[i];
for(int i = 1;i <= n; i++) {
v[n + i] = v[i] + l;
t[n + i] = t[i];
}
for(int i = 0;i <= nmax * 2; i++)
for(int j = 0; j <= nmax * 2; j++)
for(int h = 0; h <= nmax; h++)
dp[i][j][h][0] = dp[i][j][h][1] = inf;
dp[n][n][(abs(l - v[n]) <= t[n])][0] = fabs(l - v[n]);
dp[n + 1][n + 1][(abs(l - v[n + 1]) <= t[n + 1])][0] = fabs(l - v[n + 1]);
int result = 0;
for(int dif = 0; dif < n; dif++)
for(int i = 1;i <= 2 * n; i++){
int j = i + dif;
if(j <= 2 * n){
for(int k = 0; k <= dif + 1; k++){
ll time = dp[i][j][k][0] + dist(i - 1, i);
update(dp[i - 1][j][k + (time <= t[i - 1])][0], time);
time = dp[i][j][k][1] + dist(i - 1, j);
update(dp[i - 1][j][k + (time <= t[i - 1])][0], time);
time = dp[i][j][k][0] + dist(j + 1, i);
update(dp[i][j + 1][k + (time <= t[j + 1])][1], time);
time = dp[i][j][k][1] + dist(j + 1, j);
update(dp[i][j + 1][k + (time <= t[j + 1])][1], time);
if(dp[i][j][k][0] <= inf - 5 || dp[i][j][k][1] <= inf - 5)
result = max(result, k);
}
}
}
cout << result;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
518008 KB |
Output is correct |
2 |
Correct |
254 ms |
518008 KB |
Output is correct |
3 |
Correct |
256 ms |
517956 KB |
Output is correct |
4 |
Correct |
257 ms |
518008 KB |
Output is correct |
5 |
Correct |
254 ms |
518136 KB |
Output is correct |
6 |
Correct |
257 ms |
518008 KB |
Output is correct |
7 |
Correct |
261 ms |
518008 KB |
Output is correct |
8 |
Correct |
257 ms |
517984 KB |
Output is correct |
9 |
Correct |
260 ms |
518152 KB |
Output is correct |
10 |
Correct |
265 ms |
518008 KB |
Output is correct |
11 |
Correct |
260 ms |
518044 KB |
Output is correct |
12 |
Correct |
255 ms |
518136 KB |
Output is correct |
13 |
Correct |
269 ms |
518008 KB |
Output is correct |
14 |
Correct |
249 ms |
518136 KB |
Output is correct |
15 |
Correct |
253 ms |
518008 KB |
Output is correct |
16 |
Correct |
255 ms |
518008 KB |
Output is correct |
17 |
Correct |
256 ms |
518008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
518008 KB |
Output is correct |
2 |
Correct |
254 ms |
518008 KB |
Output is correct |
3 |
Correct |
256 ms |
517956 KB |
Output is correct |
4 |
Correct |
257 ms |
518008 KB |
Output is correct |
5 |
Correct |
254 ms |
518136 KB |
Output is correct |
6 |
Correct |
257 ms |
518008 KB |
Output is correct |
7 |
Correct |
261 ms |
518008 KB |
Output is correct |
8 |
Correct |
257 ms |
517984 KB |
Output is correct |
9 |
Correct |
260 ms |
518152 KB |
Output is correct |
10 |
Correct |
265 ms |
518008 KB |
Output is correct |
11 |
Correct |
260 ms |
518044 KB |
Output is correct |
12 |
Correct |
255 ms |
518136 KB |
Output is correct |
13 |
Correct |
269 ms |
518008 KB |
Output is correct |
14 |
Correct |
249 ms |
518136 KB |
Output is correct |
15 |
Correct |
253 ms |
518008 KB |
Output is correct |
16 |
Correct |
255 ms |
518008 KB |
Output is correct |
17 |
Correct |
256 ms |
518008 KB |
Output is correct |
18 |
Correct |
258 ms |
517904 KB |
Output is correct |
19 |
Correct |
257 ms |
517948 KB |
Output is correct |
20 |
Correct |
259 ms |
518012 KB |
Output is correct |
21 |
Correct |
266 ms |
518008 KB |
Output is correct |
22 |
Correct |
262 ms |
518008 KB |
Output is correct |
23 |
Correct |
249 ms |
518008 KB |
Output is correct |
24 |
Correct |
263 ms |
517948 KB |
Output is correct |
25 |
Correct |
258 ms |
518136 KB |
Output is correct |
26 |
Correct |
251 ms |
518008 KB |
Output is correct |
27 |
Correct |
253 ms |
518008 KB |
Output is correct |
28 |
Correct |
257 ms |
517900 KB |
Output is correct |
29 |
Correct |
260 ms |
518008 KB |
Output is correct |
30 |
Correct |
264 ms |
518008 KB |
Output is correct |
31 |
Correct |
260 ms |
518008 KB |
Output is correct |
32 |
Correct |
261 ms |
518008 KB |
Output is correct |
33 |
Correct |
250 ms |
518008 KB |
Output is correct |
34 |
Correct |
256 ms |
518008 KB |
Output is correct |
35 |
Correct |
252 ms |
518008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
518008 KB |
Output is correct |
2 |
Correct |
254 ms |
518008 KB |
Output is correct |
3 |
Correct |
256 ms |
517956 KB |
Output is correct |
4 |
Correct |
257 ms |
518008 KB |
Output is correct |
5 |
Correct |
254 ms |
518136 KB |
Output is correct |
6 |
Correct |
257 ms |
518008 KB |
Output is correct |
7 |
Correct |
261 ms |
518008 KB |
Output is correct |
8 |
Correct |
257 ms |
517984 KB |
Output is correct |
9 |
Correct |
260 ms |
518152 KB |
Output is correct |
10 |
Correct |
265 ms |
518008 KB |
Output is correct |
11 |
Correct |
260 ms |
518044 KB |
Output is correct |
12 |
Correct |
255 ms |
518136 KB |
Output is correct |
13 |
Correct |
269 ms |
518008 KB |
Output is correct |
14 |
Correct |
249 ms |
518136 KB |
Output is correct |
15 |
Correct |
253 ms |
518008 KB |
Output is correct |
16 |
Correct |
255 ms |
518008 KB |
Output is correct |
17 |
Correct |
256 ms |
518008 KB |
Output is correct |
18 |
Correct |
355 ms |
518136 KB |
Output is correct |
19 |
Correct |
311 ms |
518136 KB |
Output is correct |
20 |
Correct |
277 ms |
518008 KB |
Output is correct |
21 |
Correct |
303 ms |
518008 KB |
Output is correct |
22 |
Correct |
338 ms |
518100 KB |
Output is correct |
23 |
Correct |
278 ms |
518056 KB |
Output is correct |
24 |
Correct |
272 ms |
518136 KB |
Output is correct |
25 |
Correct |
278 ms |
518008 KB |
Output is correct |
26 |
Correct |
272 ms |
518008 KB |
Output is correct |
27 |
Correct |
274 ms |
517904 KB |
Output is correct |
28 |
Correct |
272 ms |
518008 KB |
Output is correct |
29 |
Correct |
279 ms |
517988 KB |
Output is correct |
30 |
Correct |
266 ms |
518008 KB |
Output is correct |
31 |
Correct |
267 ms |
518008 KB |
Output is correct |
32 |
Correct |
264 ms |
518008 KB |
Output is correct |
33 |
Correct |
265 ms |
518012 KB |
Output is correct |
34 |
Correct |
257 ms |
518008 KB |
Output is correct |
35 |
Correct |
263 ms |
518008 KB |
Output is correct |
36 |
Correct |
262 ms |
518036 KB |
Output is correct |
37 |
Correct |
274 ms |
518008 KB |
Output is correct |
38 |
Correct |
259 ms |
518008 KB |
Output is correct |
39 |
Correct |
271 ms |
518008 KB |
Output is correct |
40 |
Correct |
259 ms |
518112 KB |
Output is correct |
41 |
Correct |
390 ms |
518136 KB |
Output is correct |
42 |
Correct |
346 ms |
518072 KB |
Output is correct |
43 |
Correct |
388 ms |
518136 KB |
Output is correct |
44 |
Correct |
326 ms |
517952 KB |
Output is correct |
45 |
Correct |
387 ms |
518008 KB |
Output is correct |
46 |
Correct |
332 ms |
518008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
518008 KB |
Output is correct |
2 |
Correct |
254 ms |
518008 KB |
Output is correct |
3 |
Correct |
256 ms |
517956 KB |
Output is correct |
4 |
Correct |
257 ms |
518008 KB |
Output is correct |
5 |
Correct |
254 ms |
518136 KB |
Output is correct |
6 |
Correct |
257 ms |
518008 KB |
Output is correct |
7 |
Correct |
261 ms |
518008 KB |
Output is correct |
8 |
Correct |
257 ms |
517984 KB |
Output is correct |
9 |
Correct |
260 ms |
518152 KB |
Output is correct |
10 |
Correct |
265 ms |
518008 KB |
Output is correct |
11 |
Correct |
260 ms |
518044 KB |
Output is correct |
12 |
Correct |
255 ms |
518136 KB |
Output is correct |
13 |
Correct |
269 ms |
518008 KB |
Output is correct |
14 |
Correct |
249 ms |
518136 KB |
Output is correct |
15 |
Correct |
253 ms |
518008 KB |
Output is correct |
16 |
Correct |
255 ms |
518008 KB |
Output is correct |
17 |
Correct |
256 ms |
518008 KB |
Output is correct |
18 |
Correct |
258 ms |
517904 KB |
Output is correct |
19 |
Correct |
257 ms |
517948 KB |
Output is correct |
20 |
Correct |
259 ms |
518012 KB |
Output is correct |
21 |
Correct |
266 ms |
518008 KB |
Output is correct |
22 |
Correct |
262 ms |
518008 KB |
Output is correct |
23 |
Correct |
249 ms |
518008 KB |
Output is correct |
24 |
Correct |
263 ms |
517948 KB |
Output is correct |
25 |
Correct |
258 ms |
518136 KB |
Output is correct |
26 |
Correct |
251 ms |
518008 KB |
Output is correct |
27 |
Correct |
253 ms |
518008 KB |
Output is correct |
28 |
Correct |
257 ms |
517900 KB |
Output is correct |
29 |
Correct |
260 ms |
518008 KB |
Output is correct |
30 |
Correct |
264 ms |
518008 KB |
Output is correct |
31 |
Correct |
260 ms |
518008 KB |
Output is correct |
32 |
Correct |
261 ms |
518008 KB |
Output is correct |
33 |
Correct |
250 ms |
518008 KB |
Output is correct |
34 |
Correct |
256 ms |
518008 KB |
Output is correct |
35 |
Correct |
252 ms |
518008 KB |
Output is correct |
36 |
Correct |
355 ms |
518136 KB |
Output is correct |
37 |
Correct |
311 ms |
518136 KB |
Output is correct |
38 |
Correct |
277 ms |
518008 KB |
Output is correct |
39 |
Correct |
303 ms |
518008 KB |
Output is correct |
40 |
Correct |
338 ms |
518100 KB |
Output is correct |
41 |
Correct |
278 ms |
518056 KB |
Output is correct |
42 |
Correct |
272 ms |
518136 KB |
Output is correct |
43 |
Correct |
278 ms |
518008 KB |
Output is correct |
44 |
Correct |
272 ms |
518008 KB |
Output is correct |
45 |
Correct |
274 ms |
517904 KB |
Output is correct |
46 |
Correct |
272 ms |
518008 KB |
Output is correct |
47 |
Correct |
279 ms |
517988 KB |
Output is correct |
48 |
Correct |
266 ms |
518008 KB |
Output is correct |
49 |
Correct |
267 ms |
518008 KB |
Output is correct |
50 |
Correct |
264 ms |
518008 KB |
Output is correct |
51 |
Correct |
265 ms |
518012 KB |
Output is correct |
52 |
Correct |
257 ms |
518008 KB |
Output is correct |
53 |
Correct |
263 ms |
518008 KB |
Output is correct |
54 |
Correct |
262 ms |
518036 KB |
Output is correct |
55 |
Correct |
274 ms |
518008 KB |
Output is correct |
56 |
Correct |
259 ms |
518008 KB |
Output is correct |
57 |
Correct |
271 ms |
518008 KB |
Output is correct |
58 |
Correct |
259 ms |
518112 KB |
Output is correct |
59 |
Correct |
390 ms |
518136 KB |
Output is correct |
60 |
Correct |
346 ms |
518072 KB |
Output is correct |
61 |
Correct |
388 ms |
518136 KB |
Output is correct |
62 |
Correct |
326 ms |
517952 KB |
Output is correct |
63 |
Correct |
387 ms |
518008 KB |
Output is correct |
64 |
Correct |
332 ms |
518008 KB |
Output is correct |
65 |
Correct |
374 ms |
518008 KB |
Output is correct |
66 |
Correct |
363 ms |
518008 KB |
Output is correct |
67 |
Correct |
347 ms |
518008 KB |
Output is correct |
68 |
Correct |
338 ms |
518136 KB |
Output is correct |
69 |
Correct |
371 ms |
518008 KB |
Output is correct |
70 |
Correct |
364 ms |
518072 KB |
Output is correct |
71 |
Correct |
358 ms |
518136 KB |
Output is correct |
72 |
Correct |
363 ms |
518040 KB |
Output is correct |
73 |
Correct |
356 ms |
518020 KB |
Output is correct |
74 |
Correct |
363 ms |
518008 KB |
Output is correct |
75 |
Correct |
358 ms |
518132 KB |
Output is correct |
76 |
Correct |
386 ms |
518008 KB |
Output is correct |
77 |
Correct |
378 ms |
518008 KB |
Output is correct |
78 |
Correct |
342 ms |
518008 KB |
Output is correct |
79 |
Correct |
348 ms |
518008 KB |
Output is correct |
80 |
Correct |
377 ms |
518008 KB |
Output is correct |
81 |
Correct |
347 ms |
518200 KB |
Output is correct |
82 |
Correct |
354 ms |
518008 KB |
Output is correct |
83 |
Correct |
394 ms |
518008 KB |
Output is correct |
84 |
Correct |
357 ms |
518008 KB |
Output is correct |
85 |
Correct |
379 ms |
518136 KB |
Output is correct |
86 |
Correct |
372 ms |
518008 KB |
Output is correct |
87 |
Correct |
363 ms |
518136 KB |
Output is correct |
88 |
Correct |
389 ms |
518264 KB |
Output is correct |
89 |
Correct |
398 ms |
518524 KB |
Output is correct |
90 |
Correct |
362 ms |
518008 KB |
Output is correct |
91 |
Correct |
392 ms |
518460 KB |
Output is correct |
92 |
Correct |
389 ms |
518268 KB |
Output is correct |
93 |
Correct |
392 ms |
518008 KB |
Output is correct |