#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 205, INF = 4e18+9;
struct stamp{
ll x, t;
};
ll dp[maxn][maxn][maxn][2];
void solve(){
int n, L;
cin >> n >> L;
vector<stamp> a(n+2);
for(int i = 1; i <= n; i++){
cin >> a[i].x;
}
for(int i = 1; i <= n; i++){
cin >> a[i].t;
}
a[0] = {0, INF};
a[n+1] = {0, INF};
auto C = [&](int i, int j) -> ll{
if(a[i].x < a[j].x) swap(i, j);
return min(a[i].x - a[j].x, L+(a[j].x-a[i].x));
};
auto chmin = [&](ll &a, ll b) -> void{
a = min(a, b);
};
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
for(int k = 0; k <= n; k++){
dp[i][j][k][0] = dp[i][j][k][1] = INF;
}
}
}
dp[1][n][0][0] = dp[1][n][0][1] = 0;
for(int len = n-1; len >= 0; len--){
for(int i = 1; i <= n-len+1; i++){
int j = i+len-1;
for(int k = 0; k <= n; k++){
if(i > 1) chmin(dp[i][j][k][0], dp[i-1][j][k][0] + C(i-1, i-1-1));
if(j < n) chmin(dp[i][j][k][1], dp[i][j+1][k][1] + C(j+1, j+1+1));
if(i > 1) chmin(dp[i][j][k][0], dp[i-1][j][k][1] + C(j+1, i-1));
if(j < n) chmin(dp[i][j][k][1], dp[i][j+1][k][0] + C(i-1, j+1));
if(k == 0) continue;
if(i > 1 && dp[i-1][j][k-1][0] + C(i-1, i-1-1) <= a[i-1].t) chmin(dp[i][j][k][0], dp[i-1][j][k-1][0] + C(i-1, i-1-1));
if(j < n && dp[i][j+1][k-1][1] + C(j+1, j+1+1) <= a[j+1].t) chmin(dp[i][j][k][1], dp[i][j+1][k-1][1] + C(j+1, j+1+1));
if(i > 1 && dp[i-1][j][k-1][1] + C(j+1, i-1) <= a[i-1].t) chmin(dp[i][j][k][0], dp[i-1][j][k-1][1] + C(j+1, i-1));
if(j < n && dp[i][j+1][k-1][0] + C(i-1, j+1) <= a[j+1].t) chmin(dp[i][j][k][1], dp[i][j+1][k-1][0] + C(i-1, j+1));
}
}
}
int ans = 0;
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
for(int k = n; k >= 0; k--){
if(min(dp[i][j][k][0], dp[i][j][k][1]) < INF){
ans = max(ans, k);
}
}
}
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
860 KB |
Output is correct |
13 |
Correct |
0 ms |
860 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
860 KB |
Output is correct |
13 |
Correct |
0 ms |
860 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
0 ms |
860 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Correct |
0 ms |
1116 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
1116 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
26 |
Correct |
0 ms |
1116 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
1116 KB |
Output is correct |
30 |
Correct |
1 ms |
1232 KB |
Output is correct |
31 |
Correct |
0 ms |
1116 KB |
Output is correct |
32 |
Correct |
0 ms |
1116 KB |
Output is correct |
33 |
Correct |
1 ms |
1116 KB |
Output is correct |
34 |
Correct |
1 ms |
1116 KB |
Output is correct |
35 |
Correct |
1 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
860 KB |
Output is correct |
13 |
Correct |
0 ms |
860 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
89 ms |
104900 KB |
Output is correct |
19 |
Correct |
48 ms |
63580 KB |
Output is correct |
20 |
Correct |
22 ms |
34140 KB |
Output is correct |
21 |
Correct |
42 ms |
60280 KB |
Output is correct |
22 |
Correct |
62 ms |
78020 KB |
Output is correct |
23 |
Correct |
17 ms |
29016 KB |
Output is correct |
24 |
Correct |
15 ms |
22616 KB |
Output is correct |
25 |
Correct |
17 ms |
28252 KB |
Output is correct |
26 |
Correct |
6 ms |
10848 KB |
Output is correct |
27 |
Correct |
24 ms |
29728 KB |
Output is correct |
28 |
Correct |
13 ms |
21084 KB |
Output is correct |
29 |
Correct |
19 ms |
30316 KB |
Output is correct |
30 |
Correct |
14 ms |
23900 KB |
Output is correct |
31 |
Correct |
19 ms |
28496 KB |
Output is correct |
32 |
Correct |
8 ms |
14940 KB |
Output is correct |
33 |
Correct |
17 ms |
28296 KB |
Output is correct |
34 |
Correct |
5 ms |
10076 KB |
Output is correct |
35 |
Correct |
17 ms |
27704 KB |
Output is correct |
36 |
Correct |
7 ms |
13264 KB |
Output is correct |
37 |
Correct |
19 ms |
29544 KB |
Output is correct |
38 |
Correct |
9 ms |
16220 KB |
Output is correct |
39 |
Correct |
19 ms |
30940 KB |
Output is correct |
40 |
Correct |
10 ms |
18192 KB |
Output is correct |
41 |
Correct |
114 ms |
129428 KB |
Output is correct |
42 |
Correct |
68 ms |
87352 KB |
Output is correct |
43 |
Correct |
109 ms |
129616 KB |
Output is correct |
44 |
Correct |
67 ms |
86200 KB |
Output is correct |
45 |
Correct |
112 ms |
129368 KB |
Output is correct |
46 |
Correct |
66 ms |
87128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
860 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
860 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
860 KB |
Output is correct |
13 |
Correct |
0 ms |
860 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
1 ms |
1116 KB |
Output is correct |
19 |
Correct |
0 ms |
860 KB |
Output is correct |
20 |
Correct |
1 ms |
860 KB |
Output is correct |
21 |
Correct |
0 ms |
1116 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
1116 KB |
Output is correct |
24 |
Correct |
1 ms |
1116 KB |
Output is correct |
25 |
Correct |
1 ms |
1116 KB |
Output is correct |
26 |
Correct |
0 ms |
1116 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
1 ms |
1116 KB |
Output is correct |
30 |
Correct |
1 ms |
1232 KB |
Output is correct |
31 |
Correct |
0 ms |
1116 KB |
Output is correct |
32 |
Correct |
0 ms |
1116 KB |
Output is correct |
33 |
Correct |
1 ms |
1116 KB |
Output is correct |
34 |
Correct |
1 ms |
1116 KB |
Output is correct |
35 |
Correct |
1 ms |
1116 KB |
Output is correct |
36 |
Correct |
89 ms |
104900 KB |
Output is correct |
37 |
Correct |
48 ms |
63580 KB |
Output is correct |
38 |
Correct |
22 ms |
34140 KB |
Output is correct |
39 |
Correct |
42 ms |
60280 KB |
Output is correct |
40 |
Correct |
62 ms |
78020 KB |
Output is correct |
41 |
Correct |
17 ms |
29016 KB |
Output is correct |
42 |
Correct |
15 ms |
22616 KB |
Output is correct |
43 |
Correct |
17 ms |
28252 KB |
Output is correct |
44 |
Correct |
6 ms |
10848 KB |
Output is correct |
45 |
Correct |
24 ms |
29728 KB |
Output is correct |
46 |
Correct |
13 ms |
21084 KB |
Output is correct |
47 |
Correct |
19 ms |
30316 KB |
Output is correct |
48 |
Correct |
14 ms |
23900 KB |
Output is correct |
49 |
Correct |
19 ms |
28496 KB |
Output is correct |
50 |
Correct |
8 ms |
14940 KB |
Output is correct |
51 |
Correct |
17 ms |
28296 KB |
Output is correct |
52 |
Correct |
5 ms |
10076 KB |
Output is correct |
53 |
Correct |
17 ms |
27704 KB |
Output is correct |
54 |
Correct |
7 ms |
13264 KB |
Output is correct |
55 |
Correct |
19 ms |
29544 KB |
Output is correct |
56 |
Correct |
9 ms |
16220 KB |
Output is correct |
57 |
Correct |
19 ms |
30940 KB |
Output is correct |
58 |
Correct |
10 ms |
18192 KB |
Output is correct |
59 |
Correct |
114 ms |
129428 KB |
Output is correct |
60 |
Correct |
68 ms |
87352 KB |
Output is correct |
61 |
Correct |
109 ms |
129616 KB |
Output is correct |
62 |
Correct |
67 ms |
86200 KB |
Output is correct |
63 |
Correct |
112 ms |
129368 KB |
Output is correct |
64 |
Correct |
66 ms |
87128 KB |
Output is correct |
65 |
Correct |
106 ms |
117028 KB |
Output is correct |
66 |
Correct |
88 ms |
107304 KB |
Output is correct |
67 |
Correct |
86 ms |
102744 KB |
Output is correct |
68 |
Correct |
81 ms |
94800 KB |
Output is correct |
69 |
Correct |
102 ms |
115792 KB |
Output is correct |
70 |
Correct |
93 ms |
110928 KB |
Output is correct |
71 |
Correct |
95 ms |
111964 KB |
Output is correct |
72 |
Correct |
98 ms |
113236 KB |
Output is correct |
73 |
Correct |
83 ms |
105112 KB |
Output is correct |
74 |
Correct |
89 ms |
98124 KB |
Output is correct |
75 |
Correct |
87 ms |
108604 KB |
Output is correct |
76 |
Correct |
114 ms |
124504 KB |
Output is correct |
77 |
Correct |
110 ms |
124512 KB |
Output is correct |
78 |
Correct |
78 ms |
95884 KB |
Output is correct |
79 |
Correct |
81 ms |
99372 KB |
Output is correct |
80 |
Correct |
105 ms |
121940 KB |
Output is correct |
81 |
Correct |
87 ms |
100432 KB |
Output is correct |
82 |
Correct |
87 ms |
106264 KB |
Output is correct |
83 |
Correct |
119 ms |
129604 KB |
Output is correct |
84 |
Correct |
90 ms |
110984 KB |
Output is correct |
85 |
Correct |
99 ms |
120656 KB |
Output is correct |
86 |
Correct |
107 ms |
118100 KB |
Output is correct |
87 |
Correct |
87 ms |
108372 KB |
Output is correct |
88 |
Correct |
111 ms |
130900 KB |
Output is correct |
89 |
Correct |
110 ms |
130676 KB |
Output is correct |
90 |
Correct |
88 ms |
109792 KB |
Output is correct |
91 |
Correct |
128 ms |
130896 KB |
Output is correct |
92 |
Correct |
114 ms |
130896 KB |
Output is correct |
93 |
Correct |
127 ms |
128320 KB |
Output is correct |