#include <bits/stdc++.h>
#define int long long
#define IO ios::sync_with_stdio(0), cin.tie(0)
#define FOR(i, a, b) for (int i = a, I = b; i <= I; i++)
using namespace std;
using pii = pair<int, int>;
void dbg() {;}
template<class T, class ...U>
void dbg(T a, U ...b) { cout << a << " "; dbg(b...); }
void ent() { cout << "\n"; }
const int INF = 1e17;
const int N = 205;
int a[N], t[N];
int dp[2][N][N][N];
signed main() {
IO;
int n, len;
cin >> n >> len;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) cin >> t[i];
int ans = 0;
fill(&dp[0][0][0][0], &dp[0][0][0][0] + 2 * N * N * N, INF);
dp[0][0][0][n] = 0;
for (int i = 0; i < n; i++) {
for (int r = n; r >= 1; r--) {
// Left : 0
for (int l = 0; l <= r; l++) {
if (dp[0][i][l][r] < INF) {
int ti, nxt_i;
ti = dp[0][i][l][r] + (a[l + 1] - a[l]);
nxt_i = i + (ti <= t[l + 1]);
dp[0][nxt_i][l + 1][r] = min(dp[0][nxt_i][l + 1][r], ti);
ti = dp[0][i][l][r] + (a[l] - 0 + len - a[r]);
nxt_i = i + (ti <= t[r]);
dp[1][nxt_i][l + 1][r] = min(dp[1][nxt_i][l + 1][r], ti);
}
}
// Right : 1
for (int l = 0; l <= r; l++) {
if (dp[1][i][l][r] < INF) {
int ti, nxt_i;
ti = dp[1][i][l][r] + (len - a[r] + a[l] - 0);
nxt_i = i + (ti <= t[l]);
dp[0][nxt_i][l][r - 1] = min(dp[0][nxt_i][l][r - 1], ti);
ti = dp[1][i][l][r] + (a[r] - a[r - 1]);
nxt_i = i + (ti <= t[r - 1]);
dp[1][nxt_i][l][r - 1] = min(dp[1][nxt_i][l][r - 1], ti);
}
}
}
}
for (int i = 1; i <= n; i++)
for (int l = 1; l <= n; l++)
for (int r = l; r <= n; r++)
if (dp[0][i][l][r] < INF || dp[1][i][l][r] < INF)
ans = max(ans, i);
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
135248 KB |
Output is correct |
2 |
Correct |
27 ms |
135256 KB |
Output is correct |
3 |
Correct |
27 ms |
135260 KB |
Output is correct |
4 |
Correct |
26 ms |
135172 KB |
Output is correct |
5 |
Correct |
26 ms |
135252 KB |
Output is correct |
6 |
Correct |
25 ms |
135252 KB |
Output is correct |
7 |
Correct |
27 ms |
135252 KB |
Output is correct |
8 |
Correct |
26 ms |
135168 KB |
Output is correct |
9 |
Correct |
33 ms |
135112 KB |
Output is correct |
10 |
Correct |
28 ms |
135252 KB |
Output is correct |
11 |
Correct |
26 ms |
135248 KB |
Output is correct |
12 |
Correct |
26 ms |
135212 KB |
Output is correct |
13 |
Correct |
25 ms |
135248 KB |
Output is correct |
14 |
Correct |
25 ms |
135172 KB |
Output is correct |
15 |
Correct |
26 ms |
135512 KB |
Output is correct |
16 |
Correct |
27 ms |
135144 KB |
Output is correct |
17 |
Correct |
26 ms |
135252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
135248 KB |
Output is correct |
2 |
Correct |
27 ms |
135256 KB |
Output is correct |
3 |
Correct |
27 ms |
135260 KB |
Output is correct |
4 |
Correct |
26 ms |
135172 KB |
Output is correct |
5 |
Correct |
26 ms |
135252 KB |
Output is correct |
6 |
Correct |
25 ms |
135252 KB |
Output is correct |
7 |
Correct |
27 ms |
135252 KB |
Output is correct |
8 |
Correct |
26 ms |
135168 KB |
Output is correct |
9 |
Correct |
33 ms |
135112 KB |
Output is correct |
10 |
Correct |
28 ms |
135252 KB |
Output is correct |
11 |
Correct |
26 ms |
135248 KB |
Output is correct |
12 |
Correct |
26 ms |
135212 KB |
Output is correct |
13 |
Correct |
25 ms |
135248 KB |
Output is correct |
14 |
Correct |
25 ms |
135172 KB |
Output is correct |
15 |
Correct |
26 ms |
135512 KB |
Output is correct |
16 |
Correct |
27 ms |
135144 KB |
Output is correct |
17 |
Correct |
26 ms |
135252 KB |
Output is correct |
18 |
Correct |
26 ms |
135120 KB |
Output is correct |
19 |
Correct |
27 ms |
135188 KB |
Output is correct |
20 |
Correct |
27 ms |
135252 KB |
Output is correct |
21 |
Correct |
26 ms |
135160 KB |
Output is correct |
22 |
Correct |
26 ms |
135260 KB |
Output is correct |
23 |
Correct |
25 ms |
135196 KB |
Output is correct |
24 |
Correct |
30 ms |
135464 KB |
Output is correct |
25 |
Correct |
27 ms |
135260 KB |
Output is correct |
26 |
Correct |
28 ms |
135228 KB |
Output is correct |
27 |
Correct |
26 ms |
135252 KB |
Output is correct |
28 |
Correct |
27 ms |
135260 KB |
Output is correct |
29 |
Correct |
26 ms |
135152 KB |
Output is correct |
30 |
Correct |
26 ms |
135252 KB |
Output is correct |
31 |
Correct |
26 ms |
135248 KB |
Output is correct |
32 |
Correct |
27 ms |
135248 KB |
Output is correct |
33 |
Correct |
26 ms |
135312 KB |
Output is correct |
34 |
Correct |
30 ms |
135252 KB |
Output is correct |
35 |
Correct |
26 ms |
135232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
135248 KB |
Output is correct |
2 |
Correct |
27 ms |
135256 KB |
Output is correct |
3 |
Correct |
27 ms |
135260 KB |
Output is correct |
4 |
Correct |
26 ms |
135172 KB |
Output is correct |
5 |
Correct |
26 ms |
135252 KB |
Output is correct |
6 |
Correct |
25 ms |
135252 KB |
Output is correct |
7 |
Correct |
27 ms |
135252 KB |
Output is correct |
8 |
Correct |
26 ms |
135168 KB |
Output is correct |
9 |
Correct |
33 ms |
135112 KB |
Output is correct |
10 |
Correct |
28 ms |
135252 KB |
Output is correct |
11 |
Correct |
26 ms |
135248 KB |
Output is correct |
12 |
Correct |
26 ms |
135212 KB |
Output is correct |
13 |
Correct |
25 ms |
135248 KB |
Output is correct |
14 |
Correct |
25 ms |
135172 KB |
Output is correct |
15 |
Correct |
26 ms |
135512 KB |
Output is correct |
16 |
Correct |
27 ms |
135144 KB |
Output is correct |
17 |
Correct |
26 ms |
135252 KB |
Output is correct |
18 |
Correct |
66 ms |
135232 KB |
Output is correct |
19 |
Correct |
48 ms |
135248 KB |
Output is correct |
20 |
Correct |
34 ms |
135224 KB |
Output is correct |
21 |
Correct |
43 ms |
135312 KB |
Output is correct |
22 |
Correct |
58 ms |
135324 KB |
Output is correct |
23 |
Correct |
33 ms |
135092 KB |
Output is correct |
24 |
Correct |
29 ms |
135256 KB |
Output is correct |
25 |
Correct |
34 ms |
135120 KB |
Output is correct |
26 |
Correct |
28 ms |
135248 KB |
Output is correct |
27 |
Correct |
34 ms |
135248 KB |
Output is correct |
28 |
Correct |
29 ms |
135252 KB |
Output is correct |
29 |
Correct |
33 ms |
135252 KB |
Output is correct |
30 |
Correct |
30 ms |
135176 KB |
Output is correct |
31 |
Correct |
32 ms |
135260 KB |
Output is correct |
32 |
Correct |
29 ms |
135252 KB |
Output is correct |
33 |
Correct |
32 ms |
135248 KB |
Output is correct |
34 |
Correct |
28 ms |
135096 KB |
Output is correct |
35 |
Correct |
29 ms |
135252 KB |
Output is correct |
36 |
Correct |
31 ms |
135260 KB |
Output is correct |
37 |
Correct |
31 ms |
135208 KB |
Output is correct |
38 |
Correct |
33 ms |
135252 KB |
Output is correct |
39 |
Correct |
30 ms |
135260 KB |
Output is correct |
40 |
Correct |
29 ms |
135248 KB |
Output is correct |
41 |
Correct |
80 ms |
135304 KB |
Output is correct |
42 |
Correct |
41 ms |
135256 KB |
Output is correct |
43 |
Correct |
82 ms |
135224 KB |
Output is correct |
44 |
Correct |
40 ms |
135372 KB |
Output is correct |
45 |
Correct |
81 ms |
135124 KB |
Output is correct |
46 |
Correct |
41 ms |
135244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
135248 KB |
Output is correct |
2 |
Correct |
27 ms |
135256 KB |
Output is correct |
3 |
Correct |
27 ms |
135260 KB |
Output is correct |
4 |
Correct |
26 ms |
135172 KB |
Output is correct |
5 |
Correct |
26 ms |
135252 KB |
Output is correct |
6 |
Correct |
25 ms |
135252 KB |
Output is correct |
7 |
Correct |
27 ms |
135252 KB |
Output is correct |
8 |
Correct |
26 ms |
135168 KB |
Output is correct |
9 |
Correct |
33 ms |
135112 KB |
Output is correct |
10 |
Correct |
28 ms |
135252 KB |
Output is correct |
11 |
Correct |
26 ms |
135248 KB |
Output is correct |
12 |
Correct |
26 ms |
135212 KB |
Output is correct |
13 |
Correct |
25 ms |
135248 KB |
Output is correct |
14 |
Correct |
25 ms |
135172 KB |
Output is correct |
15 |
Correct |
26 ms |
135512 KB |
Output is correct |
16 |
Correct |
27 ms |
135144 KB |
Output is correct |
17 |
Correct |
26 ms |
135252 KB |
Output is correct |
18 |
Correct |
26 ms |
135120 KB |
Output is correct |
19 |
Correct |
27 ms |
135188 KB |
Output is correct |
20 |
Correct |
27 ms |
135252 KB |
Output is correct |
21 |
Correct |
26 ms |
135160 KB |
Output is correct |
22 |
Correct |
26 ms |
135260 KB |
Output is correct |
23 |
Correct |
25 ms |
135196 KB |
Output is correct |
24 |
Correct |
30 ms |
135464 KB |
Output is correct |
25 |
Correct |
27 ms |
135260 KB |
Output is correct |
26 |
Correct |
28 ms |
135228 KB |
Output is correct |
27 |
Correct |
26 ms |
135252 KB |
Output is correct |
28 |
Correct |
27 ms |
135260 KB |
Output is correct |
29 |
Correct |
26 ms |
135152 KB |
Output is correct |
30 |
Correct |
26 ms |
135252 KB |
Output is correct |
31 |
Correct |
26 ms |
135248 KB |
Output is correct |
32 |
Correct |
27 ms |
135248 KB |
Output is correct |
33 |
Correct |
26 ms |
135312 KB |
Output is correct |
34 |
Correct |
30 ms |
135252 KB |
Output is correct |
35 |
Correct |
26 ms |
135232 KB |
Output is correct |
36 |
Correct |
66 ms |
135232 KB |
Output is correct |
37 |
Correct |
48 ms |
135248 KB |
Output is correct |
38 |
Correct |
34 ms |
135224 KB |
Output is correct |
39 |
Correct |
43 ms |
135312 KB |
Output is correct |
40 |
Correct |
58 ms |
135324 KB |
Output is correct |
41 |
Correct |
33 ms |
135092 KB |
Output is correct |
42 |
Correct |
29 ms |
135256 KB |
Output is correct |
43 |
Correct |
34 ms |
135120 KB |
Output is correct |
44 |
Correct |
28 ms |
135248 KB |
Output is correct |
45 |
Correct |
34 ms |
135248 KB |
Output is correct |
46 |
Correct |
29 ms |
135252 KB |
Output is correct |
47 |
Correct |
33 ms |
135252 KB |
Output is correct |
48 |
Correct |
30 ms |
135176 KB |
Output is correct |
49 |
Correct |
32 ms |
135260 KB |
Output is correct |
50 |
Correct |
29 ms |
135252 KB |
Output is correct |
51 |
Correct |
32 ms |
135248 KB |
Output is correct |
52 |
Correct |
28 ms |
135096 KB |
Output is correct |
53 |
Correct |
29 ms |
135252 KB |
Output is correct |
54 |
Correct |
31 ms |
135260 KB |
Output is correct |
55 |
Correct |
31 ms |
135208 KB |
Output is correct |
56 |
Correct |
33 ms |
135252 KB |
Output is correct |
57 |
Correct |
30 ms |
135260 KB |
Output is correct |
58 |
Correct |
29 ms |
135248 KB |
Output is correct |
59 |
Correct |
80 ms |
135304 KB |
Output is correct |
60 |
Correct |
41 ms |
135256 KB |
Output is correct |
61 |
Correct |
82 ms |
135224 KB |
Output is correct |
62 |
Correct |
40 ms |
135372 KB |
Output is correct |
63 |
Correct |
81 ms |
135124 KB |
Output is correct |
64 |
Correct |
41 ms |
135244 KB |
Output is correct |
65 |
Correct |
74 ms |
135260 KB |
Output is correct |
66 |
Correct |
67 ms |
135252 KB |
Output is correct |
67 |
Correct |
70 ms |
135312 KB |
Output is correct |
68 |
Correct |
65 ms |
135252 KB |
Output is correct |
69 |
Correct |
79 ms |
135248 KB |
Output is correct |
70 |
Correct |
87 ms |
135312 KB |
Output is correct |
71 |
Correct |
81 ms |
135316 KB |
Output is correct |
72 |
Correct |
91 ms |
135564 KB |
Output is correct |
73 |
Correct |
56 ms |
135260 KB |
Output is correct |
74 |
Correct |
67 ms |
135248 KB |
Output is correct |
75 |
Correct |
65 ms |
135316 KB |
Output is correct |
76 |
Correct |
79 ms |
135100 KB |
Output is correct |
77 |
Correct |
75 ms |
135312 KB |
Output is correct |
78 |
Correct |
61 ms |
135256 KB |
Output is correct |
79 |
Correct |
63 ms |
135256 KB |
Output is correct |
80 |
Correct |
86 ms |
135260 KB |
Output is correct |
81 |
Correct |
60 ms |
135320 KB |
Output is correct |
82 |
Correct |
57 ms |
135232 KB |
Output is correct |
83 |
Correct |
73 ms |
135248 KB |
Output is correct |
84 |
Correct |
56 ms |
135164 KB |
Output is correct |
85 |
Correct |
62 ms |
135144 KB |
Output is correct |
86 |
Correct |
65 ms |
135252 KB |
Output is correct |
87 |
Correct |
67 ms |
135316 KB |
Output is correct |
88 |
Correct |
95 ms |
135108 KB |
Output is correct |
89 |
Correct |
81 ms |
135172 KB |
Output is correct |
90 |
Correct |
43 ms |
135508 KB |
Output is correct |
91 |
Correct |
88 ms |
135252 KB |
Output is correct |
92 |
Correct |
84 ms |
135252 KB |
Output is correct |
93 |
Correct |
59 ms |
135252 KB |
Output is correct |