#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 222;
const ll inf = 1e17;
const ll mod = 1e9 + 7;
const ll block = 350;
ll dp[N][N][N][2]; // dp[l][r][stamps][left/right]
ll n,L;
ll x[N], t[N];
void to_thic_cau(){
cin >> n >> L;
x[n+1] = 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 + 1;i++){
for(int j = 0; j <= n + 1;j++){
for(int k = 0; k <= n;k++) dp[i][j][k][0] = dp[i][j][k][1] = inf;
}
}
dp[0][n+1][0][0] = 0;
for(int i = 0; i <= n + 1;i++){
for(int j = n + 1; j > i;j--){
if(i == 0 && j == n + 1) continue;
for(int k = 0; k <= n;k++){
// TH ko pick
if(i >= 1){
dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k][0] + x[i] - x[i-1]);
if(j <= n) dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k][1] + x[i] + L - x[j]);
}
if(j <= n){
dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k][1] + x[j+1] - x[j]);
dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k][0] + x[i] + L - x[j]);
}
if(k == 0) continue;
// xet TH co pick (ben trai)
if(i >= 1){
if(dp[i-1][j][k-1][0] + x[i] - x[i-1] <= t[i]){
dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k-1][0] + x[i] - x[i-1]);
}
if(j <= n){
if(dp[i-1][j][k-1][1] + x[i] + L - x[j] <= t[i]){
dp[i][j][k][0] = min(dp[i][j][k][0], dp[i-1][j][k-1][1] + x[i] + L - x[j]);
}
}
}
if(j <= n){
if(dp[i][j+1][k-1][1] + x[j+1] - x[j] <= t[j]){
dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k-1][1] + x[j+1] - x[j]);
}
if(dp[i][j+1][k-1][0] + x[i] + L - x[j] <= t[j]){
dp[i][j][k][1] = min(dp[i][j][k][1], dp[i][j+1][k-1][0] + x[i] + L - x[j]);
}
}
}
}
}
ll res = 0;
for(int i = 0; i <= n;i++){
for(int j = 0; j <= n + 1;j++){
for(int k = 0; k <= n;k++){
if(dp[i][j][k][0] < inf || dp[i][j][k][1] < inf) res = max(res, k * 1ll);
}
}
}
cout << res << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
10588 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
10584 KB |
Output is correct |
17 |
Correct |
1 ms |
10584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
10588 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
10584 KB |
Output is correct |
17 |
Correct |
1 ms |
10584 KB |
Output is correct |
18 |
Correct |
1 ms |
12636 KB |
Output is correct |
19 |
Correct |
1 ms |
10588 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
1 ms |
10844 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
10844 KB |
Output is correct |
24 |
Correct |
2 ms |
12756 KB |
Output is correct |
25 |
Correct |
1 ms |
10844 KB |
Output is correct |
26 |
Correct |
1 ms |
10844 KB |
Output is correct |
27 |
Correct |
1 ms |
8536 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
1 ms |
12636 KB |
Output is correct |
30 |
Correct |
2 ms |
12636 KB |
Output is correct |
31 |
Correct |
1 ms |
10844 KB |
Output is correct |
32 |
Correct |
2 ms |
10584 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
1 ms |
10844 KB |
Output is correct |
35 |
Correct |
1 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
10588 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
10584 KB |
Output is correct |
17 |
Correct |
1 ms |
10584 KB |
Output is correct |
18 |
Correct |
86 ms |
117072 KB |
Output is correct |
19 |
Correct |
45 ms |
74332 KB |
Output is correct |
20 |
Correct |
20 ms |
44124 KB |
Output is correct |
21 |
Correct |
44 ms |
69908 KB |
Output is correct |
22 |
Correct |
52 ms |
89048 KB |
Output is correct |
23 |
Correct |
17 ms |
39004 KB |
Output is correct |
24 |
Correct |
14 ms |
31324 KB |
Output is correct |
25 |
Correct |
19 ms |
37212 KB |
Output is correct |
26 |
Correct |
6 ms |
21336 KB |
Output is correct |
27 |
Correct |
19 ms |
38236 KB |
Output is correct |
28 |
Correct |
12 ms |
31112 KB |
Output is correct |
29 |
Correct |
19 ms |
40284 KB |
Output is correct |
30 |
Correct |
14 ms |
32600 KB |
Output is correct |
31 |
Correct |
15 ms |
37212 KB |
Output is correct |
32 |
Correct |
7 ms |
25228 KB |
Output is correct |
33 |
Correct |
18 ms |
38512 KB |
Output is correct |
34 |
Correct |
6 ms |
19036 KB |
Output is correct |
35 |
Correct |
17 ms |
36444 KB |
Output is correct |
36 |
Correct |
7 ms |
22108 KB |
Output is correct |
37 |
Correct |
16 ms |
39548 KB |
Output is correct |
38 |
Correct |
9 ms |
24924 KB |
Output is correct |
39 |
Correct |
21 ms |
39516 KB |
Output is correct |
40 |
Correct |
11 ms |
26972 KB |
Output is correct |
41 |
Correct |
112 ms |
142460 KB |
Output is correct |
42 |
Correct |
60 ms |
98644 KB |
Output is correct |
43 |
Correct |
90 ms |
142704 KB |
Output is correct |
44 |
Correct |
62 ms |
97060 KB |
Output is correct |
45 |
Correct |
89 ms |
142712 KB |
Output is correct |
46 |
Correct |
58 ms |
98132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
10588 KB |
Output is correct |
9 |
Correct |
1 ms |
10588 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6488 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
10584 KB |
Output is correct |
17 |
Correct |
1 ms |
10584 KB |
Output is correct |
18 |
Correct |
1 ms |
12636 KB |
Output is correct |
19 |
Correct |
1 ms |
10588 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
1 ms |
10844 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
1 ms |
10844 KB |
Output is correct |
24 |
Correct |
2 ms |
12756 KB |
Output is correct |
25 |
Correct |
1 ms |
10844 KB |
Output is correct |
26 |
Correct |
1 ms |
10844 KB |
Output is correct |
27 |
Correct |
1 ms |
8536 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
1 ms |
12636 KB |
Output is correct |
30 |
Correct |
2 ms |
12636 KB |
Output is correct |
31 |
Correct |
1 ms |
10844 KB |
Output is correct |
32 |
Correct |
2 ms |
10584 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
1 ms |
10844 KB |
Output is correct |
35 |
Correct |
1 ms |
10844 KB |
Output is correct |
36 |
Correct |
86 ms |
117072 KB |
Output is correct |
37 |
Correct |
45 ms |
74332 KB |
Output is correct |
38 |
Correct |
20 ms |
44124 KB |
Output is correct |
39 |
Correct |
44 ms |
69908 KB |
Output is correct |
40 |
Correct |
52 ms |
89048 KB |
Output is correct |
41 |
Correct |
17 ms |
39004 KB |
Output is correct |
42 |
Correct |
14 ms |
31324 KB |
Output is correct |
43 |
Correct |
19 ms |
37212 KB |
Output is correct |
44 |
Correct |
6 ms |
21336 KB |
Output is correct |
45 |
Correct |
19 ms |
38236 KB |
Output is correct |
46 |
Correct |
12 ms |
31112 KB |
Output is correct |
47 |
Correct |
19 ms |
40284 KB |
Output is correct |
48 |
Correct |
14 ms |
32600 KB |
Output is correct |
49 |
Correct |
15 ms |
37212 KB |
Output is correct |
50 |
Correct |
7 ms |
25228 KB |
Output is correct |
51 |
Correct |
18 ms |
38512 KB |
Output is correct |
52 |
Correct |
6 ms |
19036 KB |
Output is correct |
53 |
Correct |
17 ms |
36444 KB |
Output is correct |
54 |
Correct |
7 ms |
22108 KB |
Output is correct |
55 |
Correct |
16 ms |
39548 KB |
Output is correct |
56 |
Correct |
9 ms |
24924 KB |
Output is correct |
57 |
Correct |
21 ms |
39516 KB |
Output is correct |
58 |
Correct |
11 ms |
26972 KB |
Output is correct |
59 |
Correct |
112 ms |
142460 KB |
Output is correct |
60 |
Correct |
60 ms |
98644 KB |
Output is correct |
61 |
Correct |
90 ms |
142704 KB |
Output is correct |
62 |
Correct |
62 ms |
97060 KB |
Output is correct |
63 |
Correct |
89 ms |
142712 KB |
Output is correct |
64 |
Correct |
58 ms |
98132 KB |
Output is correct |
65 |
Correct |
84 ms |
129104 KB |
Output is correct |
66 |
Correct |
78 ms |
119120 KB |
Output is correct |
67 |
Correct |
75 ms |
114768 KB |
Output is correct |
68 |
Correct |
80 ms |
106064 KB |
Output is correct |
69 |
Correct |
86 ms |
127936 KB |
Output is correct |
70 |
Correct |
80 ms |
122832 KB |
Output is correct |
71 |
Correct |
82 ms |
123988 KB |
Output is correct |
72 |
Correct |
90 ms |
125456 KB |
Output is correct |
73 |
Correct |
75 ms |
116572 KB |
Output is correct |
74 |
Correct |
77 ms |
109580 KB |
Output is correct |
75 |
Correct |
74 ms |
120400 KB |
Output is correct |
76 |
Correct |
89 ms |
137044 KB |
Output is correct |
77 |
Correct |
81 ms |
137040 KB |
Output is correct |
78 |
Correct |
68 ms |
107088 KB |
Output is correct |
79 |
Correct |
71 ms |
111192 KB |
Output is correct |
80 |
Correct |
85 ms |
134480 KB |
Output is correct |
81 |
Correct |
74 ms |
111964 KB |
Output is correct |
82 |
Correct |
76 ms |
117760 KB |
Output is correct |
83 |
Correct |
90 ms |
142416 KB |
Output is correct |
84 |
Correct |
80 ms |
122696 KB |
Output is correct |
85 |
Correct |
106 ms |
132948 KB |
Output is correct |
86 |
Correct |
107 ms |
130496 KB |
Output is correct |
87 |
Correct |
77 ms |
120656 KB |
Output is correct |
88 |
Correct |
96 ms |
143716 KB |
Output is correct |
89 |
Correct |
91 ms |
143680 KB |
Output is correct |
90 |
Correct |
75 ms |
121680 KB |
Output is correct |
91 |
Correct |
92 ms |
143956 KB |
Output is correct |
92 |
Correct |
114 ms |
143876 KB |
Output is correct |
93 |
Correct |
94 ms |
141392 KB |
Output is correct |