#include<bits/stdc++.h>
using namespace std;
int n,l,x[401],t[401],odp;
int dp[201][201][201][2];
int odl(int a,int b)
{
return min(abs(x[a]-x[b]),min(abs(l-x[a]+x[b]),abs(l-x[b]+x[a])));
}
int main()
{
scanf("%d%d",&n,&l);
for(int i=1;i<=n;++i)
scanf("%d",&x[i]);
for(int i=1;i<=n;++i)
scanf("%d",&t[i]);
for(int i=0;i<=n;++i)
{
for(int j=0;j+i<=n;++j)
{
for(int k=0;k<=j+i;++k)
{
dp[i][j][k][0]=1500000000;
dp[i][j][k][1]=1500000000;
if(i)
{
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][j][k][0]+odl(i-1,i));
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][j][k][1]+odl(n+1-j,i));
if(k)
{
if(dp[i-1][j][k-1][0]+odl(i-1,i)<=t[i])
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][j][k-1][0]+odl(i-1,i));
if(dp[i-1][j][k-1][1]+odl(n+1-j,i)<=t[i])
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][j][k-1][1]+odl(n+1-j,i));
}
}
if(j)
{
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j-1][k][0]+odl(i,n+1-j));
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j-1][k][1]+odl(n+1-j+1,n+1-j));
if(k)
{
if(dp[i][j-1][k-1][0]+odl(i,n+1-j)<=t[n+1-j])
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j-1][k-1][0]+odl(i,n+1-j));
if(dp[i][j-1][k-1][1]+odl(n+1-j+1,n+1-j)<=t[n+1-j])
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j-1][k-1][1]+odl(n+1-j+1,n+1-j));
}
}
if(dp[i][j][k][0]<1500000000)
odp=max(odp,k);
if(dp[i][j][k][1]<1500000000)
odp=max(odp,k);
if(i==j&&j==k&&k==0)
{
dp[i][j][k][0]=0;
dp[i][j][k][1]=0;
}
}
dp[i][j][i+j+1][0]=1500000000;
dp[i][j][i+j+1][1]=1500000000;
}
}
printf("%d",odp);
return 0;
}
Compilation message
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d%d",&n,&l);
| ~~~~~^~~~~~~~~~~~~~
ho_t3.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d",&x[i]);
| ~~~~~^~~~~~~~~~~~
ho_t3.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d",&t[i]);
| ~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
556 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
488 KB |
Output is correct |
14 |
Correct |
0 ms |
312 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
556 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
488 KB |
Output is correct |
14 |
Correct |
0 ms |
312 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
448 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
444 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
576 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
444 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
572 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
556 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
488 KB |
Output is correct |
14 |
Correct |
0 ms |
312 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
116 ms |
26600 KB |
Output is correct |
19 |
Correct |
40 ms |
16296 KB |
Output is correct |
20 |
Correct |
22 ms |
8888 KB |
Output is correct |
21 |
Correct |
52 ms |
15408 KB |
Output is correct |
22 |
Correct |
50 ms |
19916 KB |
Output is correct |
23 |
Correct |
14 ms |
7636 KB |
Output is correct |
24 |
Correct |
9 ms |
6076 KB |
Output is correct |
25 |
Correct |
12 ms |
7488 KB |
Output is correct |
26 |
Correct |
4 ms |
3064 KB |
Output is correct |
27 |
Correct |
14 ms |
7772 KB |
Output is correct |
28 |
Correct |
22 ms |
5652 KB |
Output is correct |
29 |
Correct |
16 ms |
7904 KB |
Output is correct |
30 |
Correct |
11 ms |
6328 KB |
Output is correct |
31 |
Correct |
12 ms |
7508 KB |
Output is correct |
32 |
Correct |
6 ms |
4052 KB |
Output is correct |
33 |
Correct |
14 ms |
7476 KB |
Output is correct |
34 |
Correct |
4 ms |
2900 KB |
Output is correct |
35 |
Correct |
14 ms |
7252 KB |
Output is correct |
36 |
Correct |
4 ms |
3668 KB |
Output is correct |
37 |
Correct |
13 ms |
7784 KB |
Output is correct |
38 |
Correct |
8 ms |
4436 KB |
Output is correct |
39 |
Correct |
13 ms |
8120 KB |
Output is correct |
40 |
Correct |
7 ms |
4948 KB |
Output is correct |
41 |
Correct |
99 ms |
32768 KB |
Output is correct |
42 |
Correct |
56 ms |
22228 KB |
Output is correct |
43 |
Correct |
114 ms |
32732 KB |
Output is correct |
44 |
Correct |
60 ms |
21936 KB |
Output is correct |
45 |
Correct |
116 ms |
32684 KB |
Output is correct |
46 |
Correct |
59 ms |
22148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
440 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
316 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
556 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
488 KB |
Output is correct |
14 |
Correct |
0 ms |
312 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
448 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
444 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
576 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
444 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
572 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
116 ms |
26600 KB |
Output is correct |
37 |
Correct |
40 ms |
16296 KB |
Output is correct |
38 |
Correct |
22 ms |
8888 KB |
Output is correct |
39 |
Correct |
52 ms |
15408 KB |
Output is correct |
40 |
Correct |
50 ms |
19916 KB |
Output is correct |
41 |
Correct |
14 ms |
7636 KB |
Output is correct |
42 |
Correct |
9 ms |
6076 KB |
Output is correct |
43 |
Correct |
12 ms |
7488 KB |
Output is correct |
44 |
Correct |
4 ms |
3064 KB |
Output is correct |
45 |
Correct |
14 ms |
7772 KB |
Output is correct |
46 |
Correct |
22 ms |
5652 KB |
Output is correct |
47 |
Correct |
16 ms |
7904 KB |
Output is correct |
48 |
Correct |
11 ms |
6328 KB |
Output is correct |
49 |
Correct |
12 ms |
7508 KB |
Output is correct |
50 |
Correct |
6 ms |
4052 KB |
Output is correct |
51 |
Correct |
14 ms |
7476 KB |
Output is correct |
52 |
Correct |
4 ms |
2900 KB |
Output is correct |
53 |
Correct |
14 ms |
7252 KB |
Output is correct |
54 |
Correct |
4 ms |
3668 KB |
Output is correct |
55 |
Correct |
13 ms |
7784 KB |
Output is correct |
56 |
Correct |
8 ms |
4436 KB |
Output is correct |
57 |
Correct |
13 ms |
8120 KB |
Output is correct |
58 |
Correct |
7 ms |
4948 KB |
Output is correct |
59 |
Correct |
99 ms |
32768 KB |
Output is correct |
60 |
Correct |
56 ms |
22228 KB |
Output is correct |
61 |
Correct |
114 ms |
32732 KB |
Output is correct |
62 |
Correct |
60 ms |
21936 KB |
Output is correct |
63 |
Correct |
116 ms |
32684 KB |
Output is correct |
64 |
Correct |
59 ms |
22148 KB |
Output is correct |
65 |
Correct |
85 ms |
29644 KB |
Output is correct |
66 |
Correct |
78 ms |
27212 KB |
Output is correct |
67 |
Correct |
72 ms |
26004 KB |
Output is correct |
68 |
Correct |
79 ms |
24108 KB |
Output is correct |
69 |
Correct |
126 ms |
29264 KB |
Output is correct |
70 |
Correct |
92 ms |
28084 KB |
Output is correct |
71 |
Correct |
94 ms |
28356 KB |
Output is correct |
72 |
Correct |
100 ms |
28660 KB |
Output is correct |
73 |
Correct |
102 ms |
26664 KB |
Output is correct |
74 |
Correct |
83 ms |
24932 KB |
Output is correct |
75 |
Correct |
90 ms |
27536 KB |
Output is correct |
76 |
Correct |
99 ms |
31496 KB |
Output is correct |
77 |
Correct |
126 ms |
31416 KB |
Output is correct |
78 |
Correct |
98 ms |
24332 KB |
Output is correct |
79 |
Correct |
68 ms |
25140 KB |
Output is correct |
80 |
Correct |
92 ms |
30796 KB |
Output is correct |
81 |
Correct |
67 ms |
25420 KB |
Output is correct |
82 |
Correct |
77 ms |
26872 KB |
Output is correct |
83 |
Correct |
103 ms |
32776 KB |
Output is correct |
84 |
Correct |
87 ms |
28108 KB |
Output is correct |
85 |
Correct |
105 ms |
30540 KB |
Output is correct |
86 |
Correct |
83 ms |
29900 KB |
Output is correct |
87 |
Correct |
93 ms |
27460 KB |
Output is correct |
88 |
Correct |
150 ms |
33032 KB |
Output is correct |
89 |
Correct |
155 ms |
33088 KB |
Output is correct |
90 |
Correct |
112 ms |
27756 KB |
Output is correct |
91 |
Correct |
107 ms |
33032 KB |
Output is correct |
92 |
Correct |
127 ms |
33084 KB |
Output is correct |
93 |
Correct |
162 ms |
32348 KB |
Output is correct |