#include <bits/stdc++.h>
using namespace std;
#define double long double
// #define int long long
#define endl "\n"
const int N = 200 + 3,oo = 1e9 + 5;
int dp[N + 1][N + 1][N + 1][2];
int x[N + 1],t[N + 1];
int n,len;
int f(int l,int r,int cnt,int side) {
if(l == n + 1 && r == 0) {
if(cnt != 0) {
return oo;
}
return 0;
}
// cout<<cnt<<endl;
if(dp[l][r][cnt][side] != -1) return dp[l][r][cnt][side];
int res = oo;
// cout<<l<<" "<<r<<" "<<cnt<<endl;
if(side == 1) {
if(r > 0) {
res = min(res,f(l,r - 1,cnt,1) + (x[r] - x[r - 1]));
res = min(res,f(l,r - 1,cnt,0) + (len - x[l]) + x[r]);
}
if(r > 0 && cnt > 0) {
int tl = f(l,r - 1,cnt - 1,1);
if(t[r] >= tl + (x[r] - x[r - 1])) {
res = min(res,tl + x[r] - x[r - 1]);
}
tl = f(l,r - 1,cnt - 1,0);
if(t[r] >= tl + (len - x[l]) + x[r]) {
res = min(res,tl + (len - x[l]) + x[r]);
}
}
return dp[l][r][cnt][side] = res;
} else {
if(l <= n) {
res = min(res,f(l + 1,r,cnt,0) + abs(x[l] - x[l + 1]));
res = min(res,f(l + 1,r,cnt,1) + (len - x[l]) + x[r]);
}
if(l <= n && cnt > 0) {
int tl = f(l + 1,r,cnt - 1,0);
if(t[l] >= tl + abs(x[l] - x[l + 1])) {
res = min(res,tl + abs(x[l] - x[l + 1]));
}
tl = f(l + 1,r,cnt - 1,1);
if(t[l] >= tl + (len - x[l]) + x[r]) {
res = min(res,tl + (len - x[l]) + x[r]);
}
}
return dp[l][r][cnt][side] = res;
}
return dp[l][r][cnt][side] = oo;
}
signed main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
memset(dp,-1,sizeof(dp));
cin>>n>>len;
for(int i = 1;i <= n;i++) {
cin>>x[i];
}
for(int i = 1;i <= n;i++) {
cin>>t[i];
}
int res = 0;
if(x[n] == len) {
res++;
n--;
}
x[0] = 0;
x[n + 1] = len;
int sum = 0;
// cout<<f(0,4,7,1)<<endl;
for(int i = 0;i <= n;i++) {
for(int j = i + 1;j <= n + 1;j++) {
for(int k = 0;k <= n;k++) {
int asd = min(f(j,i,k,0),f(j,i,k,1));
if(asd < oo) {
sum = max(sum,k);
// cout<<j<<" "<<i<<" "<<k<<endl;
}
}
}
}
cout<<res + sum<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
66772 KB |
Output is correct |
2 |
Correct |
26 ms |
66664 KB |
Output is correct |
3 |
Correct |
26 ms |
66764 KB |
Output is correct |
4 |
Correct |
26 ms |
66656 KB |
Output is correct |
5 |
Correct |
27 ms |
66688 KB |
Output is correct |
6 |
Correct |
29 ms |
66772 KB |
Output is correct |
7 |
Correct |
27 ms |
66744 KB |
Output is correct |
8 |
Correct |
27 ms |
66772 KB |
Output is correct |
9 |
Correct |
29 ms |
66636 KB |
Output is correct |
10 |
Correct |
27 ms |
66772 KB |
Output is correct |
11 |
Correct |
27 ms |
66648 KB |
Output is correct |
12 |
Correct |
27 ms |
66732 KB |
Output is correct |
13 |
Correct |
27 ms |
66772 KB |
Output is correct |
14 |
Correct |
26 ms |
66636 KB |
Output is correct |
15 |
Correct |
31 ms |
66772 KB |
Output is correct |
16 |
Correct |
26 ms |
66704 KB |
Output is correct |
17 |
Correct |
26 ms |
66668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
66772 KB |
Output is correct |
2 |
Correct |
26 ms |
66664 KB |
Output is correct |
3 |
Correct |
26 ms |
66764 KB |
Output is correct |
4 |
Correct |
26 ms |
66656 KB |
Output is correct |
5 |
Correct |
27 ms |
66688 KB |
Output is correct |
6 |
Correct |
29 ms |
66772 KB |
Output is correct |
7 |
Correct |
27 ms |
66744 KB |
Output is correct |
8 |
Correct |
27 ms |
66772 KB |
Output is correct |
9 |
Correct |
29 ms |
66636 KB |
Output is correct |
10 |
Correct |
27 ms |
66772 KB |
Output is correct |
11 |
Correct |
27 ms |
66648 KB |
Output is correct |
12 |
Correct |
27 ms |
66732 KB |
Output is correct |
13 |
Correct |
27 ms |
66772 KB |
Output is correct |
14 |
Correct |
26 ms |
66636 KB |
Output is correct |
15 |
Correct |
31 ms |
66772 KB |
Output is correct |
16 |
Correct |
26 ms |
66704 KB |
Output is correct |
17 |
Correct |
26 ms |
66668 KB |
Output is correct |
18 |
Correct |
26 ms |
66772 KB |
Output is correct |
19 |
Correct |
27 ms |
66720 KB |
Output is correct |
20 |
Correct |
26 ms |
66760 KB |
Output is correct |
21 |
Correct |
27 ms |
66772 KB |
Output is correct |
22 |
Correct |
29 ms |
66676 KB |
Output is correct |
23 |
Correct |
27 ms |
66760 KB |
Output is correct |
24 |
Correct |
27 ms |
66724 KB |
Output is correct |
25 |
Correct |
27 ms |
66744 KB |
Output is correct |
26 |
Correct |
27 ms |
66756 KB |
Output is correct |
27 |
Correct |
26 ms |
66772 KB |
Output is correct |
28 |
Correct |
26 ms |
66688 KB |
Output is correct |
29 |
Correct |
26 ms |
66752 KB |
Output is correct |
30 |
Correct |
26 ms |
66728 KB |
Output is correct |
31 |
Correct |
26 ms |
66772 KB |
Output is correct |
32 |
Correct |
27 ms |
66772 KB |
Output is correct |
33 |
Correct |
26 ms |
66748 KB |
Output is correct |
34 |
Correct |
26 ms |
66640 KB |
Output is correct |
35 |
Correct |
26 ms |
66652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
66772 KB |
Output is correct |
2 |
Correct |
26 ms |
66664 KB |
Output is correct |
3 |
Correct |
26 ms |
66764 KB |
Output is correct |
4 |
Correct |
26 ms |
66656 KB |
Output is correct |
5 |
Correct |
27 ms |
66688 KB |
Output is correct |
6 |
Correct |
29 ms |
66772 KB |
Output is correct |
7 |
Correct |
27 ms |
66744 KB |
Output is correct |
8 |
Correct |
27 ms |
66772 KB |
Output is correct |
9 |
Correct |
29 ms |
66636 KB |
Output is correct |
10 |
Correct |
27 ms |
66772 KB |
Output is correct |
11 |
Correct |
27 ms |
66648 KB |
Output is correct |
12 |
Correct |
27 ms |
66732 KB |
Output is correct |
13 |
Correct |
27 ms |
66772 KB |
Output is correct |
14 |
Correct |
26 ms |
66636 KB |
Output is correct |
15 |
Correct |
31 ms |
66772 KB |
Output is correct |
16 |
Correct |
26 ms |
66704 KB |
Output is correct |
17 |
Correct |
26 ms |
66668 KB |
Output is correct |
18 |
Correct |
185 ms |
66816 KB |
Output is correct |
19 |
Correct |
100 ms |
66772 KB |
Output is correct |
20 |
Correct |
55 ms |
66660 KB |
Output is correct |
21 |
Correct |
91 ms |
66764 KB |
Output is correct |
22 |
Correct |
122 ms |
66772 KB |
Output is correct |
23 |
Correct |
47 ms |
66772 KB |
Output is correct |
24 |
Correct |
42 ms |
66708 KB |
Output is correct |
25 |
Correct |
48 ms |
66772 KB |
Output is correct |
26 |
Correct |
32 ms |
66636 KB |
Output is correct |
27 |
Correct |
49 ms |
66780 KB |
Output is correct |
28 |
Correct |
40 ms |
66772 KB |
Output is correct |
29 |
Correct |
50 ms |
66772 KB |
Output is correct |
30 |
Correct |
42 ms |
66772 KB |
Output is correct |
31 |
Correct |
50 ms |
66716 KB |
Output is correct |
32 |
Correct |
35 ms |
66772 KB |
Output is correct |
33 |
Correct |
52 ms |
66740 KB |
Output is correct |
34 |
Correct |
31 ms |
66740 KB |
Output is correct |
35 |
Correct |
47 ms |
66772 KB |
Output is correct |
36 |
Correct |
34 ms |
66728 KB |
Output is correct |
37 |
Correct |
52 ms |
66760 KB |
Output is correct |
38 |
Correct |
36 ms |
66756 KB |
Output is correct |
39 |
Correct |
50 ms |
66764 KB |
Output is correct |
40 |
Correct |
37 ms |
66764 KB |
Output is correct |
41 |
Correct |
234 ms |
66768 KB |
Output is correct |
42 |
Correct |
143 ms |
66768 KB |
Output is correct |
43 |
Correct |
231 ms |
66736 KB |
Output is correct |
44 |
Correct |
138 ms |
66892 KB |
Output is correct |
45 |
Correct |
234 ms |
66776 KB |
Output is correct |
46 |
Correct |
136 ms |
66772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
66772 KB |
Output is correct |
2 |
Correct |
26 ms |
66664 KB |
Output is correct |
3 |
Correct |
26 ms |
66764 KB |
Output is correct |
4 |
Correct |
26 ms |
66656 KB |
Output is correct |
5 |
Correct |
27 ms |
66688 KB |
Output is correct |
6 |
Correct |
29 ms |
66772 KB |
Output is correct |
7 |
Correct |
27 ms |
66744 KB |
Output is correct |
8 |
Correct |
27 ms |
66772 KB |
Output is correct |
9 |
Correct |
29 ms |
66636 KB |
Output is correct |
10 |
Correct |
27 ms |
66772 KB |
Output is correct |
11 |
Correct |
27 ms |
66648 KB |
Output is correct |
12 |
Correct |
27 ms |
66732 KB |
Output is correct |
13 |
Correct |
27 ms |
66772 KB |
Output is correct |
14 |
Correct |
26 ms |
66636 KB |
Output is correct |
15 |
Correct |
31 ms |
66772 KB |
Output is correct |
16 |
Correct |
26 ms |
66704 KB |
Output is correct |
17 |
Correct |
26 ms |
66668 KB |
Output is correct |
18 |
Correct |
26 ms |
66772 KB |
Output is correct |
19 |
Correct |
27 ms |
66720 KB |
Output is correct |
20 |
Correct |
26 ms |
66760 KB |
Output is correct |
21 |
Correct |
27 ms |
66772 KB |
Output is correct |
22 |
Correct |
29 ms |
66676 KB |
Output is correct |
23 |
Correct |
27 ms |
66760 KB |
Output is correct |
24 |
Correct |
27 ms |
66724 KB |
Output is correct |
25 |
Correct |
27 ms |
66744 KB |
Output is correct |
26 |
Correct |
27 ms |
66756 KB |
Output is correct |
27 |
Correct |
26 ms |
66772 KB |
Output is correct |
28 |
Correct |
26 ms |
66688 KB |
Output is correct |
29 |
Correct |
26 ms |
66752 KB |
Output is correct |
30 |
Correct |
26 ms |
66728 KB |
Output is correct |
31 |
Correct |
26 ms |
66772 KB |
Output is correct |
32 |
Correct |
27 ms |
66772 KB |
Output is correct |
33 |
Correct |
26 ms |
66748 KB |
Output is correct |
34 |
Correct |
26 ms |
66640 KB |
Output is correct |
35 |
Correct |
26 ms |
66652 KB |
Output is correct |
36 |
Correct |
185 ms |
66816 KB |
Output is correct |
37 |
Correct |
100 ms |
66772 KB |
Output is correct |
38 |
Correct |
55 ms |
66660 KB |
Output is correct |
39 |
Correct |
91 ms |
66764 KB |
Output is correct |
40 |
Correct |
122 ms |
66772 KB |
Output is correct |
41 |
Correct |
47 ms |
66772 KB |
Output is correct |
42 |
Correct |
42 ms |
66708 KB |
Output is correct |
43 |
Correct |
48 ms |
66772 KB |
Output is correct |
44 |
Correct |
32 ms |
66636 KB |
Output is correct |
45 |
Correct |
49 ms |
66780 KB |
Output is correct |
46 |
Correct |
40 ms |
66772 KB |
Output is correct |
47 |
Correct |
50 ms |
66772 KB |
Output is correct |
48 |
Correct |
42 ms |
66772 KB |
Output is correct |
49 |
Correct |
50 ms |
66716 KB |
Output is correct |
50 |
Correct |
35 ms |
66772 KB |
Output is correct |
51 |
Correct |
52 ms |
66740 KB |
Output is correct |
52 |
Correct |
31 ms |
66740 KB |
Output is correct |
53 |
Correct |
47 ms |
66772 KB |
Output is correct |
54 |
Correct |
34 ms |
66728 KB |
Output is correct |
55 |
Correct |
52 ms |
66760 KB |
Output is correct |
56 |
Correct |
36 ms |
66756 KB |
Output is correct |
57 |
Correct |
50 ms |
66764 KB |
Output is correct |
58 |
Correct |
37 ms |
66764 KB |
Output is correct |
59 |
Correct |
234 ms |
66768 KB |
Output is correct |
60 |
Correct |
143 ms |
66768 KB |
Output is correct |
61 |
Correct |
231 ms |
66736 KB |
Output is correct |
62 |
Correct |
138 ms |
66892 KB |
Output is correct |
63 |
Correct |
234 ms |
66776 KB |
Output is correct |
64 |
Correct |
136 ms |
66772 KB |
Output is correct |
65 |
Correct |
209 ms |
66772 KB |
Output is correct |
66 |
Correct |
181 ms |
66776 KB |
Output is correct |
67 |
Correct |
183 ms |
66780 KB |
Output is correct |
68 |
Correct |
156 ms |
66772 KB |
Output is correct |
69 |
Correct |
207 ms |
66772 KB |
Output is correct |
70 |
Correct |
206 ms |
66888 KB |
Output is correct |
71 |
Correct |
189 ms |
66776 KB |
Output is correct |
72 |
Correct |
198 ms |
66780 KB |
Output is correct |
73 |
Correct |
176 ms |
66776 KB |
Output is correct |
74 |
Correct |
163 ms |
66772 KB |
Output is correct |
75 |
Correct |
184 ms |
66772 KB |
Output is correct |
76 |
Correct |
234 ms |
66792 KB |
Output is correct |
77 |
Correct |
227 ms |
66784 KB |
Output is correct |
78 |
Correct |
159 ms |
66772 KB |
Output is correct |
79 |
Correct |
211 ms |
66776 KB |
Output is correct |
80 |
Correct |
218 ms |
66776 KB |
Output is correct |
81 |
Correct |
162 ms |
66776 KB |
Output is correct |
82 |
Correct |
185 ms |
66672 KB |
Output is correct |
83 |
Correct |
225 ms |
66764 KB |
Output is correct |
84 |
Correct |
185 ms |
66772 KB |
Output is correct |
85 |
Correct |
210 ms |
66800 KB |
Output is correct |
86 |
Correct |
197 ms |
66772 KB |
Output is correct |
87 |
Correct |
184 ms |
66776 KB |
Output is correct |
88 |
Correct |
249 ms |
66764 KB |
Output is correct |
89 |
Correct |
238 ms |
66884 KB |
Output is correct |
90 |
Correct |
182 ms |
66764 KB |
Output is correct |
91 |
Correct |
236 ms |
66676 KB |
Output is correct |
92 |
Correct |
245 ms |
66776 KB |
Output is correct |
93 |
Correct |
230 ms |
66780 KB |
Output is correct |