#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,l;
int a[405],t[405];
int dp[405][405][205][2];
#define INF (int) 1e17
void chkmin(int &x,int y){x=x<y?x:y;}
int dis(int x,int y){return abs(a[x]-a[y]);}
bool ok(int u,int VAL){return t[u]>=VAL;}
int32_t main(){
for(int i=0; i<405; i++){
for(int j=0; j<405; j++){
for(int k=0; k<205; k++){
dp[i][j][k][0] = 1e17;
dp[i][j][k][1] = 1e17;
}
}
}
cin>>n>>l;
for(int i=1; i<=n; i++){
cin>>a[i+n];
a[i] = -(l-a[i+n]);
}
for(int i=1; i<=n; i++){
cin>>t[i]; t[i+n]=t[i];
}
for(int i=1; i<=2*n; i++){
dp[i][i][0][0] = abs(a[i]);
if(t[i]>=abs(a[i])) dp[i][i][1][0] = abs(a[i]);
}
for(int l=1; l<n; l++){
for(int x=1; x+l-1<=2*n; x++){
int y = x+l-1;
for(int k=0; k<=l; k++){
if(dp[x][y][k][0]!=1e17){
int now=x,u=0;
if(x-1&&dis(now,x-1)<=INF)chkmin(dp[x-1][y][k+ok(x-1,dp[x][y][k][u]+dis(now,x-1))][0],dp[x][y][k][u]+dis(now,x-1));
if(y+1<=2*n&&dis(now,y+1)<=INF)chkmin(dp[x][y+1][k+ok(y+1,dp[x][y][k][u]+dis(now,y+1))][1],dp[x][y][k][u]+dis(now,y+1));
}
if(dp[x][y][k][1]!=1e17){
int now=y,u=1;
if(x-1&&dis(now,x-1)<=INF)chkmin(dp[x-1][y][k+ok(x-1,dp[x][y][k][u]+dis(now,x-1))][0],dp[x][y][k][u]+dis(now,x-1));
if(y+1<=2*n&&dis(now,y+1)<=INF)chkmin(dp[x][y+1][k+ok(y+1,dp[x][y][k][u]+dis(now,y+1))][1],dp[x][y][k][u]+dis(now,y+1));
}
}
}
}
for(int k=n;k>=0;k--){
for(int x=1;x+k-1<=2*n;x++){
for(int y=x+k-1;y<=2*n;y++){
if(dp[x][y][k][0]!=INF||dp[x][y][k][1]!=INF){
cout<<k; return 0;
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
526752 KB |
Output is correct |
2 |
Correct |
265 ms |
526712 KB |
Output is correct |
3 |
Correct |
256 ms |
526712 KB |
Output is correct |
4 |
Correct |
263 ms |
526716 KB |
Output is correct |
5 |
Correct |
264 ms |
526716 KB |
Output is correct |
6 |
Correct |
256 ms |
526712 KB |
Output is correct |
7 |
Correct |
258 ms |
526712 KB |
Output is correct |
8 |
Correct |
280 ms |
526840 KB |
Output is correct |
9 |
Correct |
262 ms |
526712 KB |
Output is correct |
10 |
Correct |
262 ms |
526712 KB |
Output is correct |
11 |
Correct |
258 ms |
526712 KB |
Output is correct |
12 |
Correct |
265 ms |
526712 KB |
Output is correct |
13 |
Correct |
262 ms |
526840 KB |
Output is correct |
14 |
Correct |
255 ms |
526712 KB |
Output is correct |
15 |
Correct |
257 ms |
526584 KB |
Output is correct |
16 |
Correct |
267 ms |
526840 KB |
Output is correct |
17 |
Correct |
254 ms |
526712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
526752 KB |
Output is correct |
2 |
Correct |
265 ms |
526712 KB |
Output is correct |
3 |
Correct |
256 ms |
526712 KB |
Output is correct |
4 |
Correct |
263 ms |
526716 KB |
Output is correct |
5 |
Correct |
264 ms |
526716 KB |
Output is correct |
6 |
Correct |
256 ms |
526712 KB |
Output is correct |
7 |
Correct |
258 ms |
526712 KB |
Output is correct |
8 |
Correct |
280 ms |
526840 KB |
Output is correct |
9 |
Correct |
262 ms |
526712 KB |
Output is correct |
10 |
Correct |
262 ms |
526712 KB |
Output is correct |
11 |
Correct |
258 ms |
526712 KB |
Output is correct |
12 |
Correct |
265 ms |
526712 KB |
Output is correct |
13 |
Correct |
262 ms |
526840 KB |
Output is correct |
14 |
Correct |
255 ms |
526712 KB |
Output is correct |
15 |
Correct |
257 ms |
526584 KB |
Output is correct |
16 |
Correct |
267 ms |
526840 KB |
Output is correct |
17 |
Correct |
254 ms |
526712 KB |
Output is correct |
18 |
Correct |
263 ms |
526840 KB |
Output is correct |
19 |
Correct |
270 ms |
526712 KB |
Output is correct |
20 |
Correct |
265 ms |
526716 KB |
Output is correct |
21 |
Correct |
260 ms |
526812 KB |
Output is correct |
22 |
Correct |
270 ms |
526712 KB |
Output is correct |
23 |
Correct |
261 ms |
526712 KB |
Output is correct |
24 |
Correct |
263 ms |
526712 KB |
Output is correct |
25 |
Correct |
274 ms |
526712 KB |
Output is correct |
26 |
Correct |
262 ms |
526840 KB |
Output is correct |
27 |
Correct |
263 ms |
526712 KB |
Output is correct |
28 |
Correct |
262 ms |
526712 KB |
Output is correct |
29 |
Correct |
264 ms |
526752 KB |
Output is correct |
30 |
Correct |
267 ms |
526712 KB |
Output is correct |
31 |
Correct |
265 ms |
526712 KB |
Output is correct |
32 |
Correct |
264 ms |
526712 KB |
Output is correct |
33 |
Correct |
264 ms |
526712 KB |
Output is correct |
34 |
Correct |
268 ms |
526840 KB |
Output is correct |
35 |
Correct |
261 ms |
526712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
526752 KB |
Output is correct |
2 |
Correct |
265 ms |
526712 KB |
Output is correct |
3 |
Correct |
256 ms |
526712 KB |
Output is correct |
4 |
Correct |
263 ms |
526716 KB |
Output is correct |
5 |
Correct |
264 ms |
526716 KB |
Output is correct |
6 |
Correct |
256 ms |
526712 KB |
Output is correct |
7 |
Correct |
258 ms |
526712 KB |
Output is correct |
8 |
Correct |
280 ms |
526840 KB |
Output is correct |
9 |
Correct |
262 ms |
526712 KB |
Output is correct |
10 |
Correct |
262 ms |
526712 KB |
Output is correct |
11 |
Correct |
258 ms |
526712 KB |
Output is correct |
12 |
Correct |
265 ms |
526712 KB |
Output is correct |
13 |
Correct |
262 ms |
526840 KB |
Output is correct |
14 |
Correct |
255 ms |
526712 KB |
Output is correct |
15 |
Correct |
257 ms |
526584 KB |
Output is correct |
16 |
Correct |
267 ms |
526840 KB |
Output is correct |
17 |
Correct |
254 ms |
526712 KB |
Output is correct |
18 |
Correct |
346 ms |
526712 KB |
Output is correct |
19 |
Correct |
304 ms |
526712 KB |
Output is correct |
20 |
Correct |
275 ms |
526712 KB |
Output is correct |
21 |
Correct |
309 ms |
526892 KB |
Output is correct |
22 |
Correct |
314 ms |
526712 KB |
Output is correct |
23 |
Correct |
280 ms |
526712 KB |
Output is correct |
24 |
Correct |
272 ms |
526712 KB |
Output is correct |
25 |
Correct |
277 ms |
526712 KB |
Output is correct |
26 |
Correct |
270 ms |
526840 KB |
Output is correct |
27 |
Correct |
278 ms |
526712 KB |
Output is correct |
28 |
Correct |
263 ms |
526712 KB |
Output is correct |
29 |
Correct |
273 ms |
526780 KB |
Output is correct |
30 |
Correct |
263 ms |
526712 KB |
Output is correct |
31 |
Correct |
282 ms |
526840 KB |
Output is correct |
32 |
Correct |
264 ms |
526712 KB |
Output is correct |
33 |
Correct |
277 ms |
526712 KB |
Output is correct |
34 |
Correct |
266 ms |
526744 KB |
Output is correct |
35 |
Correct |
270 ms |
526712 KB |
Output is correct |
36 |
Correct |
266 ms |
526712 KB |
Output is correct |
37 |
Correct |
301 ms |
526712 KB |
Output is correct |
38 |
Correct |
272 ms |
526712 KB |
Output is correct |
39 |
Correct |
276 ms |
527008 KB |
Output is correct |
40 |
Correct |
262 ms |
526712 KB |
Output is correct |
41 |
Correct |
389 ms |
526840 KB |
Output is correct |
42 |
Correct |
324 ms |
526712 KB |
Output is correct |
43 |
Correct |
386 ms |
526712 KB |
Output is correct |
44 |
Correct |
328 ms |
526712 KB |
Output is correct |
45 |
Correct |
391 ms |
526712 KB |
Output is correct |
46 |
Correct |
327 ms |
526712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
255 ms |
526752 KB |
Output is correct |
2 |
Correct |
265 ms |
526712 KB |
Output is correct |
3 |
Correct |
256 ms |
526712 KB |
Output is correct |
4 |
Correct |
263 ms |
526716 KB |
Output is correct |
5 |
Correct |
264 ms |
526716 KB |
Output is correct |
6 |
Correct |
256 ms |
526712 KB |
Output is correct |
7 |
Correct |
258 ms |
526712 KB |
Output is correct |
8 |
Correct |
280 ms |
526840 KB |
Output is correct |
9 |
Correct |
262 ms |
526712 KB |
Output is correct |
10 |
Correct |
262 ms |
526712 KB |
Output is correct |
11 |
Correct |
258 ms |
526712 KB |
Output is correct |
12 |
Correct |
265 ms |
526712 KB |
Output is correct |
13 |
Correct |
262 ms |
526840 KB |
Output is correct |
14 |
Correct |
255 ms |
526712 KB |
Output is correct |
15 |
Correct |
257 ms |
526584 KB |
Output is correct |
16 |
Correct |
267 ms |
526840 KB |
Output is correct |
17 |
Correct |
254 ms |
526712 KB |
Output is correct |
18 |
Correct |
263 ms |
526840 KB |
Output is correct |
19 |
Correct |
270 ms |
526712 KB |
Output is correct |
20 |
Correct |
265 ms |
526716 KB |
Output is correct |
21 |
Correct |
260 ms |
526812 KB |
Output is correct |
22 |
Correct |
270 ms |
526712 KB |
Output is correct |
23 |
Correct |
261 ms |
526712 KB |
Output is correct |
24 |
Correct |
263 ms |
526712 KB |
Output is correct |
25 |
Correct |
274 ms |
526712 KB |
Output is correct |
26 |
Correct |
262 ms |
526840 KB |
Output is correct |
27 |
Correct |
263 ms |
526712 KB |
Output is correct |
28 |
Correct |
262 ms |
526712 KB |
Output is correct |
29 |
Correct |
264 ms |
526752 KB |
Output is correct |
30 |
Correct |
267 ms |
526712 KB |
Output is correct |
31 |
Correct |
265 ms |
526712 KB |
Output is correct |
32 |
Correct |
264 ms |
526712 KB |
Output is correct |
33 |
Correct |
264 ms |
526712 KB |
Output is correct |
34 |
Correct |
268 ms |
526840 KB |
Output is correct |
35 |
Correct |
261 ms |
526712 KB |
Output is correct |
36 |
Correct |
346 ms |
526712 KB |
Output is correct |
37 |
Correct |
304 ms |
526712 KB |
Output is correct |
38 |
Correct |
275 ms |
526712 KB |
Output is correct |
39 |
Correct |
309 ms |
526892 KB |
Output is correct |
40 |
Correct |
314 ms |
526712 KB |
Output is correct |
41 |
Correct |
280 ms |
526712 KB |
Output is correct |
42 |
Correct |
272 ms |
526712 KB |
Output is correct |
43 |
Correct |
277 ms |
526712 KB |
Output is correct |
44 |
Correct |
270 ms |
526840 KB |
Output is correct |
45 |
Correct |
278 ms |
526712 KB |
Output is correct |
46 |
Correct |
263 ms |
526712 KB |
Output is correct |
47 |
Correct |
273 ms |
526780 KB |
Output is correct |
48 |
Correct |
263 ms |
526712 KB |
Output is correct |
49 |
Correct |
282 ms |
526840 KB |
Output is correct |
50 |
Correct |
264 ms |
526712 KB |
Output is correct |
51 |
Correct |
277 ms |
526712 KB |
Output is correct |
52 |
Correct |
266 ms |
526744 KB |
Output is correct |
53 |
Correct |
270 ms |
526712 KB |
Output is correct |
54 |
Correct |
266 ms |
526712 KB |
Output is correct |
55 |
Correct |
301 ms |
526712 KB |
Output is correct |
56 |
Correct |
272 ms |
526712 KB |
Output is correct |
57 |
Correct |
276 ms |
527008 KB |
Output is correct |
58 |
Correct |
262 ms |
526712 KB |
Output is correct |
59 |
Correct |
389 ms |
526840 KB |
Output is correct |
60 |
Correct |
324 ms |
526712 KB |
Output is correct |
61 |
Correct |
386 ms |
526712 KB |
Output is correct |
62 |
Correct |
328 ms |
526712 KB |
Output is correct |
63 |
Correct |
391 ms |
526712 KB |
Output is correct |
64 |
Correct |
327 ms |
526712 KB |
Output is correct |
65 |
Correct |
365 ms |
526712 KB |
Output is correct |
66 |
Correct |
360 ms |
526712 KB |
Output is correct |
67 |
Correct |
354 ms |
526712 KB |
Output is correct |
68 |
Correct |
341 ms |
526712 KB |
Output is correct |
69 |
Correct |
372 ms |
526712 KB |
Output is correct |
70 |
Correct |
371 ms |
526956 KB |
Output is correct |
71 |
Correct |
360 ms |
526712 KB |
Output is correct |
72 |
Correct |
376 ms |
526988 KB |
Output is correct |
73 |
Correct |
329 ms |
526780 KB |
Output is correct |
74 |
Correct |
357 ms |
526712 KB |
Output is correct |
75 |
Correct |
352 ms |
526712 KB |
Output is correct |
76 |
Correct |
356 ms |
526712 KB |
Output is correct |
77 |
Correct |
367 ms |
526712 KB |
Output is correct |
78 |
Correct |
338 ms |
526712 KB |
Output is correct |
79 |
Correct |
343 ms |
526712 KB |
Output is correct |
80 |
Correct |
356 ms |
526712 KB |
Output is correct |
81 |
Correct |
335 ms |
526840 KB |
Output is correct |
82 |
Correct |
336 ms |
526712 KB |
Output is correct |
83 |
Correct |
381 ms |
526792 KB |
Output is correct |
84 |
Correct |
350 ms |
526720 KB |
Output is correct |
85 |
Correct |
336 ms |
526984 KB |
Output is correct |
86 |
Correct |
365 ms |
526712 KB |
Output is correct |
87 |
Correct |
367 ms |
526968 KB |
Output is correct |
88 |
Correct |
394 ms |
526712 KB |
Output is correct |
89 |
Correct |
398 ms |
526968 KB |
Output is correct |
90 |
Correct |
341 ms |
526712 KB |
Output is correct |
91 |
Correct |
398 ms |
526840 KB |
Output is correct |
92 |
Correct |
408 ms |
526840 KB |
Output is correct |
93 |
Correct |
381 ms |
526840 KB |
Output is correct |