#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
ll n,l;
ll dp[201][201][201][2];
int main(){
cin >> n >> l;
vector<ll> dists(n+1);
vector<ll> times(n+1);
FOR(i,1,n+1) cin >> dists[i];
FOR(i,1,n+1) cin >> times[i];
FOR(i,0,201){
FOR(j,0,201){
FOR(k,0,201){
dp[i][j][k][0] = 10000000000000;
dp[i][j][k][1] = 10000000000000;
}
}
}
dp[n][0][0][1] = 0;
// dp[n][1][0][1] = times[1];
// if (times[1] >= dists[1]) dp[n][1][1][1] = times[1];
// if (times[n] >= l-places[n]) dp[n][1][1][0] = l-places[n];
// else dp[n][1][0][0] = l-places[n];
// if (times[1] >= places[1]) dp[n][1][1][1] = places[1];
// else dp[n][1][0][1] = places[1];
FOR(k,0,n+1) FORNEG(i,n,-1) FOR(j,0,n+1){
if (i<j) continue;
if (i!=n){
dp[i][j][k][0] = min(dp[i][j][k][0], dp[i+1][j][k][0] + dists[i+1] - dists[i]);
if (k!=0){
ll tm = dists[i+1] - dists[i] + dp[i+1][j][k-1][0];
if (tm <= times[i]){
dp[i][j][k][0] = min(dp[i][j][k][0], tm);
}
}
dp[i][j][k][1] = min(dp[i][j][k][1], dp[i+1][j][k][0] + l + dists[j] - dists[i+1]);
if (k!=0){
ll tm = dp[i+1][j][k-1][0] + l + dists[j] - dists[i+1];
if (tm <= times[j]){
dp[i][j][k][1] = min(dp[i][j][k][1], tm);
}
}
}
if (j!=0){
dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j-1][k][1] + dists[j] - dists[j-1]);
if (k!=0){
ll tm = dists[j] - dists[j-1] + dp[i][j-1][k-1][1];
if (tm <= times[j]){
dp[i][j][k][1] = min(dp[i][j][k][1], tm);
}
}
dp[i][j][k][0] = min(dp[i][j][k][0], dp[i][j-1][k][1] + l + dists[j-1] - dists[i]);
if (k!=0){
ll tm = dp[i][j-1][k-1][1] + l + dists[j-1] - dists[i];
if (tm <= times[i]){
dp[i][j][k][0] = min(dp[i][j][k][0], tm);
}
}
}
}
ll ans = 0;
FOR(i,0,201) FOR(j,0,201) FOR(k,0,201) FOR(m,0,2){
if (dp[i][j][k][m] < 10000000000000) ans = max(ans, k);
}
// if (ans==7){
// cout << n << " " << l << endl;
// FOR(i,0,n+1) cout << dists[i] << " ";
// cout << endl;
// FOR(i,0,n+1) cout << times[i] << " ";
// }
// else cout << ans;
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
127408 KB |
Output is correct |
2 |
Correct |
63 ms |
127348 KB |
Output is correct |
3 |
Correct |
66 ms |
127328 KB |
Output is correct |
4 |
Correct |
66 ms |
127292 KB |
Output is correct |
5 |
Correct |
62 ms |
127344 KB |
Output is correct |
6 |
Correct |
65 ms |
127408 KB |
Output is correct |
7 |
Correct |
64 ms |
127332 KB |
Output is correct |
8 |
Correct |
62 ms |
127416 KB |
Output is correct |
9 |
Correct |
63 ms |
127384 KB |
Output is correct |
10 |
Correct |
64 ms |
127400 KB |
Output is correct |
11 |
Correct |
65 ms |
127308 KB |
Output is correct |
12 |
Correct |
63 ms |
127408 KB |
Output is correct |
13 |
Correct |
66 ms |
127408 KB |
Output is correct |
14 |
Correct |
63 ms |
127320 KB |
Output is correct |
15 |
Correct |
63 ms |
127400 KB |
Output is correct |
16 |
Correct |
63 ms |
127308 KB |
Output is correct |
17 |
Correct |
63 ms |
127308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
127408 KB |
Output is correct |
2 |
Correct |
63 ms |
127348 KB |
Output is correct |
3 |
Correct |
66 ms |
127328 KB |
Output is correct |
4 |
Correct |
66 ms |
127292 KB |
Output is correct |
5 |
Correct |
62 ms |
127344 KB |
Output is correct |
6 |
Correct |
65 ms |
127408 KB |
Output is correct |
7 |
Correct |
64 ms |
127332 KB |
Output is correct |
8 |
Correct |
62 ms |
127416 KB |
Output is correct |
9 |
Correct |
63 ms |
127384 KB |
Output is correct |
10 |
Correct |
64 ms |
127400 KB |
Output is correct |
11 |
Correct |
65 ms |
127308 KB |
Output is correct |
12 |
Correct |
63 ms |
127408 KB |
Output is correct |
13 |
Correct |
66 ms |
127408 KB |
Output is correct |
14 |
Correct |
63 ms |
127320 KB |
Output is correct |
15 |
Correct |
63 ms |
127400 KB |
Output is correct |
16 |
Correct |
63 ms |
127308 KB |
Output is correct |
17 |
Correct |
63 ms |
127308 KB |
Output is correct |
18 |
Correct |
64 ms |
127340 KB |
Output is correct |
19 |
Correct |
64 ms |
127412 KB |
Output is correct |
20 |
Correct |
65 ms |
127328 KB |
Output is correct |
21 |
Correct |
93 ms |
127408 KB |
Output is correct |
22 |
Correct |
64 ms |
127408 KB |
Output is correct |
23 |
Correct |
63 ms |
127460 KB |
Output is correct |
24 |
Correct |
68 ms |
127344 KB |
Output is correct |
25 |
Correct |
77 ms |
127312 KB |
Output is correct |
26 |
Correct |
68 ms |
127396 KB |
Output is correct |
27 |
Correct |
83 ms |
127376 KB |
Output is correct |
28 |
Correct |
72 ms |
127380 KB |
Output is correct |
29 |
Correct |
64 ms |
127408 KB |
Output is correct |
30 |
Correct |
63 ms |
127332 KB |
Output is correct |
31 |
Correct |
63 ms |
127344 KB |
Output is correct |
32 |
Correct |
78 ms |
127312 KB |
Output is correct |
33 |
Correct |
70 ms |
127412 KB |
Output is correct |
34 |
Correct |
70 ms |
127392 KB |
Output is correct |
35 |
Correct |
63 ms |
127312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
127408 KB |
Output is correct |
2 |
Correct |
63 ms |
127348 KB |
Output is correct |
3 |
Correct |
66 ms |
127328 KB |
Output is correct |
4 |
Correct |
66 ms |
127292 KB |
Output is correct |
5 |
Correct |
62 ms |
127344 KB |
Output is correct |
6 |
Correct |
65 ms |
127408 KB |
Output is correct |
7 |
Correct |
64 ms |
127332 KB |
Output is correct |
8 |
Correct |
62 ms |
127416 KB |
Output is correct |
9 |
Correct |
63 ms |
127384 KB |
Output is correct |
10 |
Correct |
64 ms |
127400 KB |
Output is correct |
11 |
Correct |
65 ms |
127308 KB |
Output is correct |
12 |
Correct |
63 ms |
127408 KB |
Output is correct |
13 |
Correct |
66 ms |
127408 KB |
Output is correct |
14 |
Correct |
63 ms |
127320 KB |
Output is correct |
15 |
Correct |
63 ms |
127400 KB |
Output is correct |
16 |
Correct |
63 ms |
127308 KB |
Output is correct |
17 |
Correct |
63 ms |
127308 KB |
Output is correct |
18 |
Correct |
100 ms |
127420 KB |
Output is correct |
19 |
Correct |
84 ms |
127300 KB |
Output is correct |
20 |
Correct |
75 ms |
127404 KB |
Output is correct |
21 |
Correct |
79 ms |
127420 KB |
Output is correct |
22 |
Correct |
87 ms |
127404 KB |
Output is correct |
23 |
Correct |
71 ms |
127360 KB |
Output is correct |
24 |
Correct |
72 ms |
127328 KB |
Output is correct |
25 |
Correct |
73 ms |
127328 KB |
Output is correct |
26 |
Correct |
65 ms |
127456 KB |
Output is correct |
27 |
Correct |
74 ms |
127412 KB |
Output is correct |
28 |
Correct |
66 ms |
127416 KB |
Output is correct |
29 |
Correct |
72 ms |
127384 KB |
Output is correct |
30 |
Correct |
66 ms |
127344 KB |
Output is correct |
31 |
Correct |
68 ms |
127300 KB |
Output is correct |
32 |
Correct |
67 ms |
127332 KB |
Output is correct |
33 |
Correct |
77 ms |
127436 KB |
Output is correct |
34 |
Correct |
64 ms |
127392 KB |
Output is correct |
35 |
Correct |
69 ms |
127416 KB |
Output is correct |
36 |
Correct |
66 ms |
127340 KB |
Output is correct |
37 |
Correct |
69 ms |
127348 KB |
Output is correct |
38 |
Correct |
68 ms |
127404 KB |
Output is correct |
39 |
Correct |
65 ms |
127412 KB |
Output is correct |
40 |
Correct |
68 ms |
127304 KB |
Output is correct |
41 |
Correct |
113 ms |
127380 KB |
Output is correct |
42 |
Correct |
89 ms |
127412 KB |
Output is correct |
43 |
Correct |
120 ms |
127376 KB |
Output is correct |
44 |
Correct |
102 ms |
127492 KB |
Output is correct |
45 |
Correct |
120 ms |
127500 KB |
Output is correct |
46 |
Correct |
95 ms |
127308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
127408 KB |
Output is correct |
2 |
Correct |
63 ms |
127348 KB |
Output is correct |
3 |
Correct |
66 ms |
127328 KB |
Output is correct |
4 |
Correct |
66 ms |
127292 KB |
Output is correct |
5 |
Correct |
62 ms |
127344 KB |
Output is correct |
6 |
Correct |
65 ms |
127408 KB |
Output is correct |
7 |
Correct |
64 ms |
127332 KB |
Output is correct |
8 |
Correct |
62 ms |
127416 KB |
Output is correct |
9 |
Correct |
63 ms |
127384 KB |
Output is correct |
10 |
Correct |
64 ms |
127400 KB |
Output is correct |
11 |
Correct |
65 ms |
127308 KB |
Output is correct |
12 |
Correct |
63 ms |
127408 KB |
Output is correct |
13 |
Correct |
66 ms |
127408 KB |
Output is correct |
14 |
Correct |
63 ms |
127320 KB |
Output is correct |
15 |
Correct |
63 ms |
127400 KB |
Output is correct |
16 |
Correct |
63 ms |
127308 KB |
Output is correct |
17 |
Correct |
63 ms |
127308 KB |
Output is correct |
18 |
Correct |
64 ms |
127340 KB |
Output is correct |
19 |
Correct |
64 ms |
127412 KB |
Output is correct |
20 |
Correct |
65 ms |
127328 KB |
Output is correct |
21 |
Correct |
93 ms |
127408 KB |
Output is correct |
22 |
Correct |
64 ms |
127408 KB |
Output is correct |
23 |
Correct |
63 ms |
127460 KB |
Output is correct |
24 |
Correct |
68 ms |
127344 KB |
Output is correct |
25 |
Correct |
77 ms |
127312 KB |
Output is correct |
26 |
Correct |
68 ms |
127396 KB |
Output is correct |
27 |
Correct |
83 ms |
127376 KB |
Output is correct |
28 |
Correct |
72 ms |
127380 KB |
Output is correct |
29 |
Correct |
64 ms |
127408 KB |
Output is correct |
30 |
Correct |
63 ms |
127332 KB |
Output is correct |
31 |
Correct |
63 ms |
127344 KB |
Output is correct |
32 |
Correct |
78 ms |
127312 KB |
Output is correct |
33 |
Correct |
70 ms |
127412 KB |
Output is correct |
34 |
Correct |
70 ms |
127392 KB |
Output is correct |
35 |
Correct |
63 ms |
127312 KB |
Output is correct |
36 |
Correct |
100 ms |
127420 KB |
Output is correct |
37 |
Correct |
84 ms |
127300 KB |
Output is correct |
38 |
Correct |
75 ms |
127404 KB |
Output is correct |
39 |
Correct |
79 ms |
127420 KB |
Output is correct |
40 |
Correct |
87 ms |
127404 KB |
Output is correct |
41 |
Correct |
71 ms |
127360 KB |
Output is correct |
42 |
Correct |
72 ms |
127328 KB |
Output is correct |
43 |
Correct |
73 ms |
127328 KB |
Output is correct |
44 |
Correct |
65 ms |
127456 KB |
Output is correct |
45 |
Correct |
74 ms |
127412 KB |
Output is correct |
46 |
Correct |
66 ms |
127416 KB |
Output is correct |
47 |
Correct |
72 ms |
127384 KB |
Output is correct |
48 |
Correct |
66 ms |
127344 KB |
Output is correct |
49 |
Correct |
68 ms |
127300 KB |
Output is correct |
50 |
Correct |
67 ms |
127332 KB |
Output is correct |
51 |
Correct |
77 ms |
127436 KB |
Output is correct |
52 |
Correct |
64 ms |
127392 KB |
Output is correct |
53 |
Correct |
69 ms |
127416 KB |
Output is correct |
54 |
Correct |
66 ms |
127340 KB |
Output is correct |
55 |
Correct |
69 ms |
127348 KB |
Output is correct |
56 |
Correct |
68 ms |
127404 KB |
Output is correct |
57 |
Correct |
65 ms |
127412 KB |
Output is correct |
58 |
Correct |
68 ms |
127304 KB |
Output is correct |
59 |
Correct |
113 ms |
127380 KB |
Output is correct |
60 |
Correct |
89 ms |
127412 KB |
Output is correct |
61 |
Correct |
120 ms |
127376 KB |
Output is correct |
62 |
Correct |
102 ms |
127492 KB |
Output is correct |
63 |
Correct |
120 ms |
127500 KB |
Output is correct |
64 |
Correct |
95 ms |
127308 KB |
Output is correct |
65 |
Correct |
103 ms |
127308 KB |
Output is correct |
66 |
Correct |
109 ms |
127412 KB |
Output is correct |
67 |
Correct |
94 ms |
127324 KB |
Output is correct |
68 |
Correct |
90 ms |
127364 KB |
Output is correct |
69 |
Correct |
102 ms |
127352 KB |
Output is correct |
70 |
Correct |
105 ms |
127312 KB |
Output is correct |
71 |
Correct |
101 ms |
127384 KB |
Output is correct |
72 |
Correct |
111 ms |
127416 KB |
Output is correct |
73 |
Correct |
98 ms |
127436 KB |
Output is correct |
74 |
Correct |
94 ms |
127384 KB |
Output is correct |
75 |
Correct |
98 ms |
127376 KB |
Output is correct |
76 |
Correct |
106 ms |
127416 KB |
Output is correct |
77 |
Correct |
105 ms |
127464 KB |
Output is correct |
78 |
Correct |
91 ms |
127320 KB |
Output is correct |
79 |
Correct |
107 ms |
127340 KB |
Output is correct |
80 |
Correct |
105 ms |
127412 KB |
Output is correct |
81 |
Correct |
93 ms |
127388 KB |
Output is correct |
82 |
Correct |
110 ms |
127396 KB |
Output is correct |
83 |
Correct |
117 ms |
127328 KB |
Output is correct |
84 |
Correct |
99 ms |
127308 KB |
Output is correct |
85 |
Correct |
104 ms |
127308 KB |
Output is correct |
86 |
Correct |
109 ms |
127420 KB |
Output is correct |
87 |
Correct |
100 ms |
127404 KB |
Output is correct |
88 |
Correct |
110 ms |
127356 KB |
Output is correct |
89 |
Correct |
112 ms |
127328 KB |
Output is correct |
90 |
Correct |
98 ms |
127332 KB |
Output is correct |
91 |
Correct |
116 ms |
127316 KB |
Output is correct |
92 |
Correct |
113 ms |
127416 KB |
Output is correct |
93 |
Correct |
105 ms |
127328 KB |
Output is correct |