#pragma GCC optimize("O3","unroll-loops")
#include<iostream>
#include<vector>
#include<cassert>
#include<algorithm>
#define ll long long
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
ll l;
cin>>n>>l;
vector<ll> pos(n+1),t(n+1);
for(int i=1;i<=n;i++) cin>>pos[i];
for(int i=1;i<=n;i++) cin>>t[i];
ll dp[201][201][201][2];
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k++){
for(int r=0;r<2;r++) dp[i][j][k][r]=1e18;
}
}
}
dp[0][0][0][0]=0;
dp[0][0][0][1]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k+=(k!=0?1:j+1)){
for(int r=j-1;r>=0;r--){
if(dp[i-1][r][k][0]+pos[j]-pos[r]<=t[j]){
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][r][k][0]+pos[j]-pos[r]);
}
if(dp[i-1][r][k][1]+pos[j]+l-pos[k]<=t[j]){
dp[i][j][k][0]=min(dp[i][j][k][0],dp[i-1][r][k][1]+pos[j]+l-pos[k]);
}
}
for(int r=k+1;r<=n;r++){
if(dp[i-1][j][r][1]+pos[r]-pos[k]<=t[k]){
//if(i==1&&j==0&&k==1) cout<<dp[i-1][j][r][0]+pos[j]+l-pos[k]<<" "<<t[k]<<"\n";
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i-1][j][r][1]+pos[r]-pos[k]);
}
if(dp[i-1][j][r][0]+pos[j]+l-pos[k]<=t[k]){
//if(i==1&&j==0&&k==1) cout<<dp[i-1][j][r][0]+pos[j]+l-pos[k]<<" "<<t[k]<<"\n";
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i-1][j][r][0]+pos[j]+l-pos[k]);
}
}
if(dp[i-1][j][0][1]+pos[0]+l-pos[k]<=t[k]){
//if(i==1&&j==0&&k==1) cout<<dp[i-1][j][0][0]+pos[j]+l-pos[k]<<" "<<t[k]<<"\n";
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i-1][j][0][1]+pos[0]+l-pos[k]);
}
if(dp[i-1][j][0][0]+pos[j]+l-pos[k]<=t[k]){
//if(i==1&&j==0&&k==1) cout<<"hehe"<<dp[i-1][j][0][0]+pos[j]+l-pos[k]<<" "<<t[k]<<"\n";
dp[i][j][k][1]=min(dp[i][j][k][1],dp[i-1][j][0][0]+pos[j]+l-pos[k]);
}
}
}
}
for(int i=n;i>=0;i--){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k++){
for(int r=0;r<=1;r++){
if(dp[i][j][k][r]<1e18){
cout<<i;
return 0;
}
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
127308 KB |
Output is correct |
2 |
Correct |
49 ms |
127504 KB |
Output is correct |
3 |
Correct |
52 ms |
127328 KB |
Output is correct |
4 |
Correct |
50 ms |
127308 KB |
Output is correct |
5 |
Correct |
55 ms |
127432 KB |
Output is correct |
6 |
Correct |
50 ms |
127364 KB |
Output is correct |
7 |
Correct |
52 ms |
127416 KB |
Output is correct |
8 |
Correct |
49 ms |
127400 KB |
Output is correct |
9 |
Correct |
53 ms |
127396 KB |
Output is correct |
10 |
Correct |
51 ms |
127432 KB |
Output is correct |
11 |
Correct |
53 ms |
127312 KB |
Output is correct |
12 |
Correct |
49 ms |
127384 KB |
Output is correct |
13 |
Correct |
57 ms |
127352 KB |
Output is correct |
14 |
Correct |
50 ms |
127404 KB |
Output is correct |
15 |
Correct |
51 ms |
127328 KB |
Output is correct |
16 |
Correct |
48 ms |
127384 KB |
Output is correct |
17 |
Correct |
49 ms |
127388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
127308 KB |
Output is correct |
2 |
Correct |
49 ms |
127504 KB |
Output is correct |
3 |
Correct |
52 ms |
127328 KB |
Output is correct |
4 |
Correct |
50 ms |
127308 KB |
Output is correct |
5 |
Correct |
55 ms |
127432 KB |
Output is correct |
6 |
Correct |
50 ms |
127364 KB |
Output is correct |
7 |
Correct |
52 ms |
127416 KB |
Output is correct |
8 |
Correct |
49 ms |
127400 KB |
Output is correct |
9 |
Correct |
53 ms |
127396 KB |
Output is correct |
10 |
Correct |
51 ms |
127432 KB |
Output is correct |
11 |
Correct |
53 ms |
127312 KB |
Output is correct |
12 |
Correct |
49 ms |
127384 KB |
Output is correct |
13 |
Correct |
57 ms |
127352 KB |
Output is correct |
14 |
Correct |
50 ms |
127404 KB |
Output is correct |
15 |
Correct |
51 ms |
127328 KB |
Output is correct |
16 |
Correct |
48 ms |
127384 KB |
Output is correct |
17 |
Correct |
49 ms |
127388 KB |
Output is correct |
18 |
Correct |
49 ms |
127416 KB |
Output is correct |
19 |
Correct |
50 ms |
127408 KB |
Output is correct |
20 |
Correct |
52 ms |
127484 KB |
Output is correct |
21 |
Correct |
52 ms |
127344 KB |
Output is correct |
22 |
Correct |
59 ms |
127328 KB |
Output is correct |
23 |
Correct |
50 ms |
127336 KB |
Output is correct |
24 |
Correct |
48 ms |
127436 KB |
Output is correct |
25 |
Correct |
49 ms |
127308 KB |
Output is correct |
26 |
Correct |
56 ms |
127356 KB |
Output is correct |
27 |
Correct |
49 ms |
127392 KB |
Output is correct |
28 |
Correct |
49 ms |
127400 KB |
Output is correct |
29 |
Correct |
51 ms |
127360 KB |
Output is correct |
30 |
Correct |
49 ms |
127432 KB |
Output is correct |
31 |
Correct |
49 ms |
127332 KB |
Output is correct |
32 |
Correct |
53 ms |
127336 KB |
Output is correct |
33 |
Correct |
49 ms |
127308 KB |
Output is correct |
34 |
Correct |
55 ms |
127316 KB |
Output is correct |
35 |
Correct |
52 ms |
127424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
127308 KB |
Output is correct |
2 |
Correct |
49 ms |
127504 KB |
Output is correct |
3 |
Correct |
52 ms |
127328 KB |
Output is correct |
4 |
Correct |
50 ms |
127308 KB |
Output is correct |
5 |
Correct |
55 ms |
127432 KB |
Output is correct |
6 |
Correct |
50 ms |
127364 KB |
Output is correct |
7 |
Correct |
52 ms |
127416 KB |
Output is correct |
8 |
Correct |
49 ms |
127400 KB |
Output is correct |
9 |
Correct |
53 ms |
127396 KB |
Output is correct |
10 |
Correct |
51 ms |
127432 KB |
Output is correct |
11 |
Correct |
53 ms |
127312 KB |
Output is correct |
12 |
Correct |
49 ms |
127384 KB |
Output is correct |
13 |
Correct |
57 ms |
127352 KB |
Output is correct |
14 |
Correct |
50 ms |
127404 KB |
Output is correct |
15 |
Correct |
51 ms |
127328 KB |
Output is correct |
16 |
Correct |
48 ms |
127384 KB |
Output is correct |
17 |
Correct |
49 ms |
127388 KB |
Output is correct |
18 |
Correct |
624 ms |
127432 KB |
Output is correct |
19 |
Correct |
270 ms |
127436 KB |
Output is correct |
20 |
Correct |
121 ms |
127432 KB |
Output is correct |
21 |
Correct |
241 ms |
127424 KB |
Output is correct |
22 |
Correct |
354 ms |
127424 KB |
Output is correct |
23 |
Correct |
130 ms |
127348 KB |
Output is correct |
24 |
Correct |
80 ms |
127368 KB |
Output is correct |
25 |
Correct |
111 ms |
127424 KB |
Output is correct |
26 |
Correct |
54 ms |
127324 KB |
Output is correct |
27 |
Correct |
115 ms |
127324 KB |
Output is correct |
28 |
Correct |
76 ms |
127428 KB |
Output is correct |
29 |
Correct |
107 ms |
127436 KB |
Output is correct |
30 |
Correct |
86 ms |
127424 KB |
Output is correct |
31 |
Correct |
99 ms |
127360 KB |
Output is correct |
32 |
Correct |
66 ms |
127316 KB |
Output is correct |
33 |
Correct |
97 ms |
127424 KB |
Output is correct |
34 |
Correct |
56 ms |
127396 KB |
Output is correct |
35 |
Correct |
88 ms |
127380 KB |
Output is correct |
36 |
Correct |
58 ms |
127352 KB |
Output is correct |
37 |
Correct |
103 ms |
127424 KB |
Output is correct |
38 |
Correct |
65 ms |
127428 KB |
Output is correct |
39 |
Correct |
97 ms |
127476 KB |
Output is correct |
40 |
Correct |
66 ms |
127344 KB |
Output is correct |
41 |
Correct |
876 ms |
127532 KB |
Output is correct |
42 |
Correct |
397 ms |
127432 KB |
Output is correct |
43 |
Correct |
889 ms |
127428 KB |
Output is correct |
44 |
Correct |
393 ms |
127432 KB |
Output is correct |
45 |
Correct |
907 ms |
127512 KB |
Output is correct |
46 |
Correct |
439 ms |
127428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
127308 KB |
Output is correct |
2 |
Correct |
49 ms |
127504 KB |
Output is correct |
3 |
Correct |
52 ms |
127328 KB |
Output is correct |
4 |
Correct |
50 ms |
127308 KB |
Output is correct |
5 |
Correct |
55 ms |
127432 KB |
Output is correct |
6 |
Correct |
50 ms |
127364 KB |
Output is correct |
7 |
Correct |
52 ms |
127416 KB |
Output is correct |
8 |
Correct |
49 ms |
127400 KB |
Output is correct |
9 |
Correct |
53 ms |
127396 KB |
Output is correct |
10 |
Correct |
51 ms |
127432 KB |
Output is correct |
11 |
Correct |
53 ms |
127312 KB |
Output is correct |
12 |
Correct |
49 ms |
127384 KB |
Output is correct |
13 |
Correct |
57 ms |
127352 KB |
Output is correct |
14 |
Correct |
50 ms |
127404 KB |
Output is correct |
15 |
Correct |
51 ms |
127328 KB |
Output is correct |
16 |
Correct |
48 ms |
127384 KB |
Output is correct |
17 |
Correct |
49 ms |
127388 KB |
Output is correct |
18 |
Correct |
49 ms |
127416 KB |
Output is correct |
19 |
Correct |
50 ms |
127408 KB |
Output is correct |
20 |
Correct |
52 ms |
127484 KB |
Output is correct |
21 |
Correct |
52 ms |
127344 KB |
Output is correct |
22 |
Correct |
59 ms |
127328 KB |
Output is correct |
23 |
Correct |
50 ms |
127336 KB |
Output is correct |
24 |
Correct |
48 ms |
127436 KB |
Output is correct |
25 |
Correct |
49 ms |
127308 KB |
Output is correct |
26 |
Correct |
56 ms |
127356 KB |
Output is correct |
27 |
Correct |
49 ms |
127392 KB |
Output is correct |
28 |
Correct |
49 ms |
127400 KB |
Output is correct |
29 |
Correct |
51 ms |
127360 KB |
Output is correct |
30 |
Correct |
49 ms |
127432 KB |
Output is correct |
31 |
Correct |
49 ms |
127332 KB |
Output is correct |
32 |
Correct |
53 ms |
127336 KB |
Output is correct |
33 |
Correct |
49 ms |
127308 KB |
Output is correct |
34 |
Correct |
55 ms |
127316 KB |
Output is correct |
35 |
Correct |
52 ms |
127424 KB |
Output is correct |
36 |
Correct |
624 ms |
127432 KB |
Output is correct |
37 |
Correct |
270 ms |
127436 KB |
Output is correct |
38 |
Correct |
121 ms |
127432 KB |
Output is correct |
39 |
Correct |
241 ms |
127424 KB |
Output is correct |
40 |
Correct |
354 ms |
127424 KB |
Output is correct |
41 |
Correct |
130 ms |
127348 KB |
Output is correct |
42 |
Correct |
80 ms |
127368 KB |
Output is correct |
43 |
Correct |
111 ms |
127424 KB |
Output is correct |
44 |
Correct |
54 ms |
127324 KB |
Output is correct |
45 |
Correct |
115 ms |
127324 KB |
Output is correct |
46 |
Correct |
76 ms |
127428 KB |
Output is correct |
47 |
Correct |
107 ms |
127436 KB |
Output is correct |
48 |
Correct |
86 ms |
127424 KB |
Output is correct |
49 |
Correct |
99 ms |
127360 KB |
Output is correct |
50 |
Correct |
66 ms |
127316 KB |
Output is correct |
51 |
Correct |
97 ms |
127424 KB |
Output is correct |
52 |
Correct |
56 ms |
127396 KB |
Output is correct |
53 |
Correct |
88 ms |
127380 KB |
Output is correct |
54 |
Correct |
58 ms |
127352 KB |
Output is correct |
55 |
Correct |
103 ms |
127424 KB |
Output is correct |
56 |
Correct |
65 ms |
127428 KB |
Output is correct |
57 |
Correct |
97 ms |
127476 KB |
Output is correct |
58 |
Correct |
66 ms |
127344 KB |
Output is correct |
59 |
Correct |
876 ms |
127532 KB |
Output is correct |
60 |
Correct |
397 ms |
127432 KB |
Output is correct |
61 |
Correct |
889 ms |
127428 KB |
Output is correct |
62 |
Correct |
393 ms |
127432 KB |
Output is correct |
63 |
Correct |
907 ms |
127512 KB |
Output is correct |
64 |
Correct |
439 ms |
127428 KB |
Output is correct |
65 |
Correct |
715 ms |
127436 KB |
Output is correct |
66 |
Correct |
605 ms |
127432 KB |
Output is correct |
67 |
Correct |
574 ms |
127428 KB |
Output is correct |
68 |
Correct |
472 ms |
127436 KB |
Output is correct |
69 |
Correct |
754 ms |
127432 KB |
Output is correct |
70 |
Correct |
1008 ms |
127432 KB |
Output is correct |
71 |
Correct |
622 ms |
127436 KB |
Output is correct |
72 |
Correct |
969 ms |
127436 KB |
Output is correct |
73 |
Correct |
554 ms |
127440 KB |
Output is correct |
74 |
Correct |
746 ms |
127436 KB |
Output is correct |
75 |
Correct |
587 ms |
127440 KB |
Output is correct |
76 |
Correct |
945 ms |
127436 KB |
Output is correct |
77 |
Correct |
741 ms |
127432 KB |
Output is correct |
78 |
Correct |
583 ms |
127544 KB |
Output is correct |
79 |
Correct |
538 ms |
127532 KB |
Output is correct |
80 |
Correct |
971 ms |
127436 KB |
Output is correct |
81 |
Correct |
516 ms |
127440 KB |
Output is correct |
82 |
Correct |
589 ms |
127496 KB |
Output is correct |
83 |
Correct |
767 ms |
127440 KB |
Output is correct |
84 |
Correct |
718 ms |
127432 KB |
Output is correct |
85 |
Correct |
714 ms |
127436 KB |
Output is correct |
86 |
Correct |
694 ms |
127436 KB |
Output is correct |
87 |
Correct |
606 ms |
127436 KB |
Output is correct |
88 |
Correct |
1128 ms |
127432 KB |
Output is correct |
89 |
Correct |
939 ms |
127432 KB |
Output is correct |
90 |
Correct |
596 ms |
127432 KB |
Output is correct |
91 |
Correct |
1026 ms |
127440 KB |
Output is correct |
92 |
Correct |
882 ms |
127440 KB |
Output is correct |
93 |
Correct |
783 ms |
127432 KB |
Output is correct |