#include<iostream>
#include<vector>
using namespace std;
vector<int> Q;
int dp[210][210][210][2];
int t[300],x[400];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,l;
cin>>n>>l;
for(int i=1;i<=n;i++)
cin>>x[i];
for(int i=1;i<=n;i++)
cin>>t[i];
for(int i=0;i<=n;i++)
for(int j=0;j<=n;j++)
for(int k=0;k<=n;k++)
{
dp[i][j][k][0]=1000000000;
dp[i][j][k][1]=1000000000;
}
x[n+1]=l;
dp[0][0][0][0]=0;
dp[0][0][0][1]=0;
for(int k=0;k<=n;k++)
{
for(int i=0;i<=n;i++)
{
for(int j=0;j+i<n;j++)
{
int ile=x[i]+(l-x[n+1-j]);
dp[i][j][k][0]=min(dp[i][j][k][1]+ile,dp[i][j][k][0]);
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i][j][k][0]+ile);
int do_lewej=dp[i][j][k][0]+(x[i+1]-x[i]);
//cout<<do_lewej<<"\n";
if(do_lewej<=t[i+1])
dp[i+1][j][k+1][0]=min(dp[i+1][j][k+1][0],do_lewej);
else dp[i+1][j][k][0]=min(dp[i+1][j][k][0],do_lewej);
int do_prawej=dp[i][j][k][1]+(x[n+1-j]-x[n+1-j-1]);
//cout<<do_prawej<<"\n";
if(do_prawej<=t[n+1-j-1])
dp[i][j+1][k+1][1]=min(dp[i][j+1][k+1][1],do_prawej);
else dp[i][j+1][k][1]=min(dp[i][j+1][k][1],do_prawej);
}
}
}
int wynik=0;
for(int i=0;i<=n;i++)
for(int j=!i;j+i<=n;j++)
for(int k=0;k<=n;k++)
if(dp[i][j][k][0]!=1e9 || dp[i][j][k][1]!=1e9)
wynik=max(wynik,k);
cout<<wynik;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
0 ms |
724 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
724 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
1 ms |
724 KB |
Output is correct |
34 |
Correct |
1 ms |
724 KB |
Output is correct |
35 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
55 ms |
54228 KB |
Output is correct |
19 |
Correct |
28 ms |
33036 KB |
Output is correct |
20 |
Correct |
14 ms |
17748 KB |
Output is correct |
21 |
Correct |
27 ms |
31232 KB |
Output is correct |
22 |
Correct |
38 ms |
40296 KB |
Output is correct |
23 |
Correct |
11 ms |
15060 KB |
Output is correct |
24 |
Correct |
8 ms |
11860 KB |
Output is correct |
25 |
Correct |
10 ms |
14804 KB |
Output is correct |
26 |
Correct |
4 ms |
5844 KB |
Output is correct |
27 |
Correct |
12 ms |
15484 KB |
Output is correct |
28 |
Correct |
8 ms |
10996 KB |
Output is correct |
29 |
Correct |
11 ms |
15800 KB |
Output is correct |
30 |
Correct |
9 ms |
12372 KB |
Output is correct |
31 |
Correct |
11 ms |
14832 KB |
Output is correct |
32 |
Correct |
5 ms |
7892 KB |
Output is correct |
33 |
Correct |
10 ms |
14804 KB |
Output is correct |
34 |
Correct |
3 ms |
5460 KB |
Output is correct |
35 |
Correct |
9 ms |
14548 KB |
Output is correct |
36 |
Correct |
4 ms |
6996 KB |
Output is correct |
37 |
Correct |
11 ms |
15424 KB |
Output is correct |
38 |
Correct |
6 ms |
8532 KB |
Output is correct |
39 |
Correct |
12 ms |
16108 KB |
Output is correct |
40 |
Correct |
6 ms |
9556 KB |
Output is correct |
41 |
Correct |
71 ms |
66848 KB |
Output is correct |
42 |
Correct |
45 ms |
45264 KB |
Output is correct |
43 |
Correct |
72 ms |
66844 KB |
Output is correct |
44 |
Correct |
41 ms |
44492 KB |
Output is correct |
45 |
Correct |
71 ms |
66848 KB |
Output is correct |
46 |
Correct |
43 ms |
45140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
0 ms |
724 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
724 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
1 ms |
724 KB |
Output is correct |
34 |
Correct |
1 ms |
724 KB |
Output is correct |
35 |
Correct |
1 ms |
724 KB |
Output is correct |
36 |
Correct |
55 ms |
54228 KB |
Output is correct |
37 |
Correct |
28 ms |
33036 KB |
Output is correct |
38 |
Correct |
14 ms |
17748 KB |
Output is correct |
39 |
Correct |
27 ms |
31232 KB |
Output is correct |
40 |
Correct |
38 ms |
40296 KB |
Output is correct |
41 |
Correct |
11 ms |
15060 KB |
Output is correct |
42 |
Correct |
8 ms |
11860 KB |
Output is correct |
43 |
Correct |
10 ms |
14804 KB |
Output is correct |
44 |
Correct |
4 ms |
5844 KB |
Output is correct |
45 |
Correct |
12 ms |
15484 KB |
Output is correct |
46 |
Correct |
8 ms |
10996 KB |
Output is correct |
47 |
Correct |
11 ms |
15800 KB |
Output is correct |
48 |
Correct |
9 ms |
12372 KB |
Output is correct |
49 |
Correct |
11 ms |
14832 KB |
Output is correct |
50 |
Correct |
5 ms |
7892 KB |
Output is correct |
51 |
Correct |
10 ms |
14804 KB |
Output is correct |
52 |
Correct |
3 ms |
5460 KB |
Output is correct |
53 |
Correct |
9 ms |
14548 KB |
Output is correct |
54 |
Correct |
4 ms |
6996 KB |
Output is correct |
55 |
Correct |
11 ms |
15424 KB |
Output is correct |
56 |
Correct |
6 ms |
8532 KB |
Output is correct |
57 |
Correct |
12 ms |
16108 KB |
Output is correct |
58 |
Correct |
6 ms |
9556 KB |
Output is correct |
59 |
Correct |
71 ms |
66848 KB |
Output is correct |
60 |
Correct |
45 ms |
45264 KB |
Output is correct |
61 |
Correct |
72 ms |
66844 KB |
Output is correct |
62 |
Correct |
41 ms |
44492 KB |
Output is correct |
63 |
Correct |
71 ms |
66848 KB |
Output is correct |
64 |
Correct |
43 ms |
45140 KB |
Output is correct |
65 |
Correct |
62 ms |
60392 KB |
Output is correct |
66 |
Correct |
55 ms |
55464 KB |
Output is correct |
67 |
Correct |
54 ms |
53068 KB |
Output is correct |
68 |
Correct |
46 ms |
48980 KB |
Output is correct |
69 |
Correct |
60 ms |
59680 KB |
Output is correct |
70 |
Correct |
57 ms |
57292 KB |
Output is correct |
71 |
Correct |
58 ms |
57812 KB |
Output is correct |
72 |
Correct |
58 ms |
58560 KB |
Output is correct |
73 |
Correct |
55 ms |
54192 KB |
Output is correct |
74 |
Correct |
48 ms |
50748 KB |
Output is correct |
75 |
Correct |
57 ms |
56072 KB |
Output is correct |
76 |
Correct |
67 ms |
64212 KB |
Output is correct |
77 |
Correct |
64 ms |
64112 KB |
Output is correct |
78 |
Correct |
48 ms |
49588 KB |
Output is correct |
79 |
Correct |
49 ms |
51284 KB |
Output is correct |
80 |
Correct |
66 ms |
62924 KB |
Output is correct |
81 |
Correct |
50 ms |
51788 KB |
Output is correct |
82 |
Correct |
56 ms |
54880 KB |
Output is correct |
83 |
Correct |
72 ms |
66772 KB |
Output is correct |
84 |
Correct |
60 ms |
57296 KB |
Output is correct |
85 |
Correct |
68 ms |
62216 KB |
Output is correct |
86 |
Correct |
64 ms |
60952 KB |
Output is correct |
87 |
Correct |
67 ms |
55960 KB |
Output is correct |
88 |
Correct |
74 ms |
67512 KB |
Output is correct |
89 |
Correct |
71 ms |
67420 KB |
Output is correct |
90 |
Correct |
56 ms |
56588 KB |
Output is correct |
91 |
Correct |
71 ms |
67516 KB |
Output is correct |
92 |
Correct |
70 ms |
67404 KB |
Output is correct |
93 |
Correct |
72 ms |
66208 KB |
Output is correct |