#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
#define ckmin(a, b) a = min(a, b)
#define ckmax(a, b) a = max(a, b)
const int maxn = 4e5 + 5;
const int INF = 1e9 + 7;
int dp[205][205][2][205]; // 0 = l, 1 = r
int x[205], t[205];
int main(void){
fastio;
int n, l;
cin>>n>>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 d = 0; d < 2; d++) for(int k = 0; k <= n; k++) dp[i][j][d][k] = INF;
dp[1][n + 1][0][(x[1] <= t[1])] = x[1];
dp[0][n][1][(l - x[n] <= t[n])] = l - x[n];
x[0] = x[n] - l, x[n + 1] = x[1] + l;
for(int len = 1; len <= n; len++){
for(int i = 0; i <= len; i++){
int j = n + 1 - (len - i);
for(int cnt = 0; cnt <= len; cnt++){
int t1 = dp[i][j][0][cnt], t2 = dp[i][j][1][cnt];
ckmin(dp[i + 1][j][0][cnt + (t1 + (x[i + 1] - x[i]) <= t[i + 1])], t1 + (x[i + 1] - x[i]));
ckmin(dp[i + 1][j][0][cnt + (t2 + (l - x[j] + x[i + 1]) <= t[i + 1])], t2 + (l - x[j] + x[i + 1]));
ckmin(dp[i][j - 1][1][cnt + (t1 + (x[i] + l - x[j - 1]) <= t[j - 1])], t1 + (x[i] + l - x[j - 1]));
ckmin(dp[i][j - 1][1][cnt + (t2 + (x[j] - x[j - 1]) <= t[j - 1])], t2 + (x[j] - x[j - 1]));
}
}
}
int ans = 0;
for(int i = 0; i <= n; i++){
for(int d = 0; d < 2; d++){
for(int cnt = 1; cnt <= n; cnt++){
if(dp[i][i + 1][d][cnt] < INF) ans = max(ans, cnt);
}
}
}
cout<<ans<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
4564 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6604 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
6632 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
4564 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6604 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
6632 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
4440 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
4440 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6608 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6488 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
4564 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6604 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
6632 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
21 ms |
60036 KB |
Output is correct |
19 |
Correct |
12 ms |
47708 KB |
Output is correct |
20 |
Correct |
7 ms |
35508 KB |
Output is correct |
21 |
Correct |
12 ms |
45660 KB |
Output is correct |
22 |
Correct |
15 ms |
51804 KB |
Output is correct |
23 |
Correct |
7 ms |
33368 KB |
Output is correct |
24 |
Correct |
5 ms |
29276 KB |
Output is correct |
25 |
Correct |
6 ms |
31324 KB |
Output is correct |
26 |
Correct |
3 ms |
20828 KB |
Output is correct |
27 |
Correct |
6 ms |
33372 KB |
Output is correct |
28 |
Correct |
4 ms |
27228 KB |
Output is correct |
29 |
Correct |
6 ms |
33372 KB |
Output is correct |
30 |
Correct |
5 ms |
29276 KB |
Output is correct |
31 |
Correct |
6 ms |
31324 KB |
Output is correct |
32 |
Correct |
4 ms |
23128 KB |
Output is correct |
33 |
Correct |
7 ms |
31324 KB |
Output is correct |
34 |
Correct |
3 ms |
18992 KB |
Output is correct |
35 |
Correct |
5 ms |
31324 KB |
Output is correct |
36 |
Correct |
3 ms |
23128 KB |
Output is correct |
37 |
Correct |
6 ms |
33372 KB |
Output is correct |
38 |
Correct |
4 ms |
25180 KB |
Output is correct |
39 |
Correct |
6 ms |
33372 KB |
Output is correct |
40 |
Correct |
5 ms |
25180 KB |
Output is correct |
41 |
Correct |
30 ms |
66536 KB |
Output is correct |
42 |
Correct |
17 ms |
56048 KB |
Output is correct |
43 |
Correct |
26 ms |
66396 KB |
Output is correct |
44 |
Correct |
18 ms |
56048 KB |
Output is correct |
45 |
Correct |
26 ms |
66396 KB |
Output is correct |
46 |
Correct |
17 ms |
56048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
4564 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
6488 KB |
Output is correct |
13 |
Correct |
1 ms |
6604 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
6632 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
4440 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
4440 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6608 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6488 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
21 ms |
60036 KB |
Output is correct |
37 |
Correct |
12 ms |
47708 KB |
Output is correct |
38 |
Correct |
7 ms |
35508 KB |
Output is correct |
39 |
Correct |
12 ms |
45660 KB |
Output is correct |
40 |
Correct |
15 ms |
51804 KB |
Output is correct |
41 |
Correct |
7 ms |
33368 KB |
Output is correct |
42 |
Correct |
5 ms |
29276 KB |
Output is correct |
43 |
Correct |
6 ms |
31324 KB |
Output is correct |
44 |
Correct |
3 ms |
20828 KB |
Output is correct |
45 |
Correct |
6 ms |
33372 KB |
Output is correct |
46 |
Correct |
4 ms |
27228 KB |
Output is correct |
47 |
Correct |
6 ms |
33372 KB |
Output is correct |
48 |
Correct |
5 ms |
29276 KB |
Output is correct |
49 |
Correct |
6 ms |
31324 KB |
Output is correct |
50 |
Correct |
4 ms |
23128 KB |
Output is correct |
51 |
Correct |
7 ms |
31324 KB |
Output is correct |
52 |
Correct |
3 ms |
18992 KB |
Output is correct |
53 |
Correct |
5 ms |
31324 KB |
Output is correct |
54 |
Correct |
3 ms |
23128 KB |
Output is correct |
55 |
Correct |
6 ms |
33372 KB |
Output is correct |
56 |
Correct |
4 ms |
25180 KB |
Output is correct |
57 |
Correct |
6 ms |
33372 KB |
Output is correct |
58 |
Correct |
5 ms |
25180 KB |
Output is correct |
59 |
Correct |
30 ms |
66536 KB |
Output is correct |
60 |
Correct |
17 ms |
56048 KB |
Output is correct |
61 |
Correct |
26 ms |
66396 KB |
Output is correct |
62 |
Correct |
18 ms |
56048 KB |
Output is correct |
63 |
Correct |
26 ms |
66396 KB |
Output is correct |
64 |
Correct |
17 ms |
56048 KB |
Output is correct |
65 |
Correct |
23 ms |
64192 KB |
Output is correct |
66 |
Correct |
22 ms |
62044 KB |
Output is correct |
67 |
Correct |
22 ms |
60132 KB |
Output is correct |
68 |
Correct |
19 ms |
58104 KB |
Output is correct |
69 |
Correct |
26 ms |
64092 KB |
Output is correct |
70 |
Correct |
22 ms |
62044 KB |
Output is correct |
71 |
Correct |
23 ms |
62044 KB |
Output is correct |
72 |
Correct |
26 ms |
64252 KB |
Output is correct |
73 |
Correct |
21 ms |
59992 KB |
Output is correct |
74 |
Correct |
22 ms |
57948 KB |
Output is correct |
75 |
Correct |
22 ms |
62044 KB |
Output is correct |
76 |
Correct |
25 ms |
66140 KB |
Output is correct |
77 |
Correct |
27 ms |
66212 KB |
Output is correct |
78 |
Correct |
19 ms |
57948 KB |
Output is correct |
79 |
Correct |
20 ms |
59996 KB |
Output is correct |
80 |
Correct |
24 ms |
66140 KB |
Output is correct |
81 |
Correct |
22 ms |
60252 KB |
Output is correct |
82 |
Correct |
21 ms |
62044 KB |
Output is correct |
83 |
Correct |
27 ms |
66396 KB |
Output is correct |
84 |
Correct |
22 ms |
62184 KB |
Output is correct |
85 |
Correct |
24 ms |
66312 KB |
Output is correct |
86 |
Correct |
23 ms |
64088 KB |
Output is correct |
87 |
Correct |
22 ms |
62044 KB |
Output is correct |
88 |
Correct |
27 ms |
66652 KB |
Output is correct |
89 |
Correct |
29 ms |
67028 KB |
Output is correct |
90 |
Correct |
22 ms |
62040 KB |
Output is correct |
91 |
Correct |
26 ms |
66904 KB |
Output is correct |
92 |
Correct |
29 ms |
66908 KB |
Output is correct |
93 |
Correct |
26 ms |
66392 KB |
Output is correct |