#include<bits/stdc++.h>
using namespace std;
const int N = 200;
const int inf = 1e9 + 10;
int v[N + 2];
int v2[N + 2];
int dp[N + 3][N + 3][N + 3][2];
int main(){
int n,nr;
int ans = 0;
cin>>n>>nr;
v[0] = 0;
v2[0] = 100;
for(int i = 1;i <= n;i++){
cin>>v[i];
}
for(int i = 1;i <= n;i++){
cin>>v2[i];
}
v[n + 1] = nr;
v2[n + 1] = 100;
n+=2;
for(int i = 0;i <= n;i++){
for(int j = 0;j <= i;j++){
for(int k = 0;k <= i;k++){
for(int p = 0;p <= 1;p++){
if(i == 0 && j == 0 && k == 0 && p == 0){
dp[i][j][k][p] = 0;
}else{
dp[i][j][k][p] = inf;
int leftid = n - 1 - (i - j);
int rightid = j;
int dist = v[rightid] + (nr - v[leftid]);
if(i == 0 || leftid <= rightid)continue;
if(p == 0){
if(leftid == n - 1)continue;
///to leftside
///from rightside
if(k != 0 && dist + dp[i - 1][j][k - 1][1] <= v2[leftid]){
dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j][k - 1][1]);
}else{
if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j][k][1]);
}
///from leftside
if(k != 0 && dp[i - 1][j][k - 1][0] + v[leftid + 1] - v[leftid] <= v2[leftid]){
dp[i][j][k][p] = min(dp[i][j][k][p],dp[i - 1][j][k - 1][0] + v[leftid + 1] - v[leftid]);
}else{
if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],dp[i - 1][j][k][0] + v[leftid + 1] - v[leftid]);
}
}else{
if(j == 0 || rightid == n)continue;
///to rightside
///from leftside
if(k != 0 && dist + dp[i - 1][j - 1][k - 1][0] <= v2[rightid]){
dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j - 1][k - 1][0]);
}else{
if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j - 1][k][0]);
}
///from rightside
if(k != 0 && (v[rightid] - v[rightid - 1]) + dp[i - 1][j - 1][k - 1][1] <= v2[rightid]){
dp[i][j][k][p] = min(dp[i][j][k][p],(v[rightid] - v[rightid - 1]) + dp[i - 1][j - 1][k - 1][1]);
}else{
if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],(v[rightid] - v[rightid - 1]) + dp[i - 1][j - 1][k][1]);
}
}
if(dp[i][j][k][p] != inf){
ans = max(ans,k);
}
//cout<<dp[i][j][k][p]<<' '<<i<<' '<<j<<' '<<k<<' '<<p<<' '<<dist<<' '<<leftid<<' '<<v[leftid + 1]<<' '<<v[leftid]<<' '<<(v[rightid] - v[rightid - 1])<<'\n';
}
}
}
}
}
cout<<ans<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6600 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6600 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
0 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6600 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
2652 KB |
Output is correct |
18 |
Correct |
31 ms |
29268 KB |
Output is correct |
19 |
Correct |
16 ms |
20824 KB |
Output is correct |
20 |
Correct |
7 ms |
11356 KB |
Output is correct |
21 |
Correct |
15 ms |
19804 KB |
Output is correct |
22 |
Correct |
22 ms |
24460 KB |
Output is correct |
23 |
Correct |
6 ms |
11864 KB |
Output is correct |
24 |
Correct |
5 ms |
8280 KB |
Output is correct |
25 |
Correct |
6 ms |
11868 KB |
Output is correct |
26 |
Correct |
2 ms |
5212 KB |
Output is correct |
27 |
Correct |
6 ms |
10208 KB |
Output is correct |
28 |
Correct |
5 ms |
9820 KB |
Output is correct |
29 |
Correct |
6 ms |
12124 KB |
Output is correct |
30 |
Correct |
5 ms |
10588 KB |
Output is correct |
31 |
Correct |
6 ms |
11864 KB |
Output is correct |
32 |
Correct |
3 ms |
8284 KB |
Output is correct |
33 |
Correct |
6 ms |
11816 KB |
Output is correct |
34 |
Correct |
2 ms |
7004 KB |
Output is correct |
35 |
Correct |
6 ms |
9816 KB |
Output is correct |
36 |
Correct |
3 ms |
7780 KB |
Output is correct |
37 |
Correct |
6 ms |
10084 KB |
Output is correct |
38 |
Correct |
3 ms |
8544 KB |
Output is correct |
39 |
Correct |
6 ms |
12408 KB |
Output is correct |
40 |
Correct |
3 ms |
7264 KB |
Output is correct |
41 |
Correct |
40 ms |
37480 KB |
Output is correct |
42 |
Correct |
23 ms |
24936 KB |
Output is correct |
43 |
Correct |
47 ms |
35656 KB |
Output is correct |
44 |
Correct |
24 ms |
26452 KB |
Output is correct |
45 |
Correct |
44 ms |
37604 KB |
Output is correct |
46 |
Correct |
23 ms |
26688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6600 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
0 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
0 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
0 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2652 KB |
Output is correct |
35 |
Correct |
1 ms |
4444 KB |
Output is correct |
36 |
Correct |
31 ms |
29268 KB |
Output is correct |
37 |
Correct |
16 ms |
20824 KB |
Output is correct |
38 |
Correct |
7 ms |
11356 KB |
Output is correct |
39 |
Correct |
15 ms |
19804 KB |
Output is correct |
40 |
Correct |
22 ms |
24460 KB |
Output is correct |
41 |
Correct |
6 ms |
11864 KB |
Output is correct |
42 |
Correct |
5 ms |
8280 KB |
Output is correct |
43 |
Correct |
6 ms |
11868 KB |
Output is correct |
44 |
Correct |
2 ms |
5212 KB |
Output is correct |
45 |
Correct |
6 ms |
10208 KB |
Output is correct |
46 |
Correct |
5 ms |
9820 KB |
Output is correct |
47 |
Correct |
6 ms |
12124 KB |
Output is correct |
48 |
Correct |
5 ms |
10588 KB |
Output is correct |
49 |
Correct |
6 ms |
11864 KB |
Output is correct |
50 |
Correct |
3 ms |
8284 KB |
Output is correct |
51 |
Correct |
6 ms |
11816 KB |
Output is correct |
52 |
Correct |
2 ms |
7004 KB |
Output is correct |
53 |
Correct |
6 ms |
9816 KB |
Output is correct |
54 |
Correct |
3 ms |
7780 KB |
Output is correct |
55 |
Correct |
6 ms |
10084 KB |
Output is correct |
56 |
Correct |
3 ms |
8544 KB |
Output is correct |
57 |
Correct |
6 ms |
12408 KB |
Output is correct |
58 |
Correct |
3 ms |
7264 KB |
Output is correct |
59 |
Correct |
40 ms |
37480 KB |
Output is correct |
60 |
Correct |
23 ms |
24936 KB |
Output is correct |
61 |
Correct |
47 ms |
35656 KB |
Output is correct |
62 |
Correct |
24 ms |
26452 KB |
Output is correct |
63 |
Correct |
44 ms |
37604 KB |
Output is correct |
64 |
Correct |
23 ms |
26688 KB |
Output is correct |
65 |
Correct |
35 ms |
32336 KB |
Output is correct |
66 |
Correct |
31 ms |
31832 KB |
Output is correct |
67 |
Correct |
29 ms |
30616 KB |
Output is correct |
68 |
Correct |
25 ms |
26704 KB |
Output is correct |
69 |
Correct |
35 ms |
32084 KB |
Output is correct |
70 |
Correct |
29 ms |
32848 KB |
Output is correct |
71 |
Correct |
31 ms |
31060 KB |
Output is correct |
72 |
Correct |
31 ms |
33372 KB |
Output is correct |
73 |
Correct |
29 ms |
31316 KB |
Output is correct |
74 |
Correct |
26 ms |
29532 KB |
Output is correct |
75 |
Correct |
30 ms |
32324 KB |
Output is correct |
76 |
Correct |
36 ms |
34384 KB |
Output is correct |
77 |
Correct |
36 ms |
36188 KB |
Output is correct |
78 |
Correct |
26 ms |
27016 KB |
Output is correct |
79 |
Correct |
28 ms |
29788 KB |
Output is correct |
80 |
Correct |
34 ms |
33620 KB |
Output is correct |
81 |
Correct |
28 ms |
30044 KB |
Output is correct |
82 |
Correct |
30 ms |
31584 KB |
Output is correct |
83 |
Correct |
38 ms |
37576 KB |
Output is correct |
84 |
Correct |
35 ms |
32852 KB |
Output is correct |
85 |
Correct |
36 ms |
33360 KB |
Output is correct |
86 |
Correct |
36 ms |
34736 KB |
Output is correct |
87 |
Correct |
45 ms |
30372 KB |
Output is correct |
88 |
Correct |
42 ms |
35828 KB |
Output is correct |
89 |
Correct |
41 ms |
37712 KB |
Output is correct |
90 |
Correct |
30 ms |
32596 KB |
Output is correct |
91 |
Correct |
38 ms |
37864 KB |
Output is correct |
92 |
Correct |
38 ms |
35924 KB |
Output is correct |
93 |
Correct |
38 ms |
37208 KB |
Output is correct |