#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " " << (x) << endl;
#define V vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int N = 202, INF = 0x3f3f3f3f;
int x[N], dp[N][N][N][2], t[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, l;
cin >> n >> l;
for(int i = 0; i < n; i++) cin >> x[i];
for(int i = 0; i < n; i++) cin >> t[i];
memset(dp, 0x3f, sizeof dp);
if(x[0] <= t[0]) dp[1][0][1][0] = x[0];
else dp[1][0][0][0] = x[0];
if(l-x[n-1] <= t[n-1]) dp[0][1][1][1] = l-x[n-1];
else dp[0][1][0][1] = l-x[n-1];
for(int i = 0; i <= n; i++) {
for(int j = 0; j + i <= n - 1; j++) {
for(int k = 0; k <= i + j; k++) {
if(dp[i][j][k][0] != INF) {
//cerr << "dp[" << i << "][" << j << "][" << k << "][0] = " << dp[i][j][k][0] << endl;
// 0
if(dp[i][j][k][0] + x[i]-x[i-1] <= t[i])
dp[i + 1][j][k+1][0] = min(dp[i + 1][j][k+1][0], dp[i][j][k][0] + x[i]-x[i-1]);
else
dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], dp[i][j][k][0] + x[i]-x[i-1]);
// 1
if(dp[i][j][k][0] + x[i - 1] + l - x[n-j-1] <= t[n-j-1])
dp[i][j + 1][k+1][1] = min(dp[i][j + 1][k+1][1], dp[i][j][k][0] + x[i - 1] + l - x[n-j-1]);
else
dp[i][j + 1][k][1] = min(dp[i][j + 1][k][1], dp[i][j][k][0] + x[i - 1] + l - x[n-j-1]);
}
if(dp[i][j][k][1] != INF) {
//cerr << "dp[" << i << "][" << j << "][" << k << "][1] = " << dp[i][j][k][1] << endl;
// 0
if(dp[i][j][k][1] + l-x[n-j]+x[i] <= t[i])
dp[i + 1][j][k+1][0] = min(dp[i + 1][j][k+1][0], dp[i][j][k][1] + l-x[n-j]+x[i]);
else
dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0], dp[i][j][k][1] + l-x[n-j]+x[i]);
// 1
if(dp[i][j][k][1] + x[n-j] - x[n-j-1] <= t[n-j-1])
dp[i][j + 1][k+1][1] = min(dp[i][j + 1][k+1][1], dp[i][j][k][1] + x[n-j] - x[n-j-1]);
else
dp[i][j + 1][k][1] = min(dp[i][j + 1][k][1], dp[i][j][k][1] + x[n-j] - x[n-j-1]);
}
}
}
}
int mx = 0;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++)
for(int k = 0; k <= i + j; k++) {
if(dp[i][j][k][0] != INF) mx = max(mx, k);
if(dp[i][j][k][1] != INF) mx = max(mx, k);
}
cout << mx << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
64896 KB |
Output is correct |
2 |
Correct |
35 ms |
64888 KB |
Output is correct |
3 |
Correct |
36 ms |
64896 KB |
Output is correct |
4 |
Correct |
37 ms |
65024 KB |
Output is correct |
5 |
Correct |
37 ms |
64896 KB |
Output is correct |
6 |
Correct |
36 ms |
64896 KB |
Output is correct |
7 |
Correct |
36 ms |
64888 KB |
Output is correct |
8 |
Correct |
36 ms |
64888 KB |
Output is correct |
9 |
Correct |
36 ms |
64888 KB |
Output is correct |
10 |
Correct |
37 ms |
64888 KB |
Output is correct |
11 |
Correct |
36 ms |
64888 KB |
Output is correct |
12 |
Correct |
36 ms |
64888 KB |
Output is correct |
13 |
Correct |
37 ms |
64896 KB |
Output is correct |
14 |
Correct |
36 ms |
64888 KB |
Output is correct |
15 |
Correct |
36 ms |
64888 KB |
Output is correct |
16 |
Correct |
36 ms |
64896 KB |
Output is correct |
17 |
Correct |
36 ms |
64888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
64896 KB |
Output is correct |
2 |
Correct |
35 ms |
64888 KB |
Output is correct |
3 |
Correct |
36 ms |
64896 KB |
Output is correct |
4 |
Correct |
37 ms |
65024 KB |
Output is correct |
5 |
Correct |
37 ms |
64896 KB |
Output is correct |
6 |
Correct |
36 ms |
64896 KB |
Output is correct |
7 |
Correct |
36 ms |
64888 KB |
Output is correct |
8 |
Correct |
36 ms |
64888 KB |
Output is correct |
9 |
Correct |
36 ms |
64888 KB |
Output is correct |
10 |
Correct |
37 ms |
64888 KB |
Output is correct |
11 |
Correct |
36 ms |
64888 KB |
Output is correct |
12 |
Correct |
36 ms |
64888 KB |
Output is correct |
13 |
Correct |
37 ms |
64896 KB |
Output is correct |
14 |
Correct |
36 ms |
64888 KB |
Output is correct |
15 |
Correct |
36 ms |
64888 KB |
Output is correct |
16 |
Correct |
36 ms |
64896 KB |
Output is correct |
17 |
Correct |
36 ms |
64888 KB |
Output is correct |
18 |
Correct |
36 ms |
64888 KB |
Output is correct |
19 |
Correct |
36 ms |
64896 KB |
Output is correct |
20 |
Correct |
36 ms |
64888 KB |
Output is correct |
21 |
Correct |
36 ms |
64888 KB |
Output is correct |
22 |
Correct |
37 ms |
64888 KB |
Output is correct |
23 |
Correct |
36 ms |
64896 KB |
Output is correct |
24 |
Correct |
37 ms |
64888 KB |
Output is correct |
25 |
Correct |
41 ms |
64888 KB |
Output is correct |
26 |
Correct |
38 ms |
64888 KB |
Output is correct |
27 |
Correct |
36 ms |
64920 KB |
Output is correct |
28 |
Correct |
36 ms |
64888 KB |
Output is correct |
29 |
Correct |
36 ms |
64896 KB |
Output is correct |
30 |
Correct |
37 ms |
64896 KB |
Output is correct |
31 |
Correct |
36 ms |
64892 KB |
Output is correct |
32 |
Correct |
36 ms |
64888 KB |
Output is correct |
33 |
Correct |
36 ms |
64888 KB |
Output is correct |
34 |
Correct |
37 ms |
64888 KB |
Output is correct |
35 |
Correct |
36 ms |
64888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
64896 KB |
Output is correct |
2 |
Correct |
35 ms |
64888 KB |
Output is correct |
3 |
Correct |
36 ms |
64896 KB |
Output is correct |
4 |
Correct |
37 ms |
65024 KB |
Output is correct |
5 |
Correct |
37 ms |
64896 KB |
Output is correct |
6 |
Correct |
36 ms |
64896 KB |
Output is correct |
7 |
Correct |
36 ms |
64888 KB |
Output is correct |
8 |
Correct |
36 ms |
64888 KB |
Output is correct |
9 |
Correct |
36 ms |
64888 KB |
Output is correct |
10 |
Correct |
37 ms |
64888 KB |
Output is correct |
11 |
Correct |
36 ms |
64888 KB |
Output is correct |
12 |
Correct |
36 ms |
64888 KB |
Output is correct |
13 |
Correct |
37 ms |
64896 KB |
Output is correct |
14 |
Correct |
36 ms |
64888 KB |
Output is correct |
15 |
Correct |
36 ms |
64888 KB |
Output is correct |
16 |
Correct |
36 ms |
64896 KB |
Output is correct |
17 |
Correct |
36 ms |
64888 KB |
Output is correct |
18 |
Correct |
61 ms |
64888 KB |
Output is correct |
19 |
Correct |
50 ms |
64888 KB |
Output is correct |
20 |
Correct |
43 ms |
64896 KB |
Output is correct |
21 |
Correct |
49 ms |
64888 KB |
Output is correct |
22 |
Correct |
56 ms |
64896 KB |
Output is correct |
23 |
Correct |
43 ms |
64888 KB |
Output is correct |
24 |
Correct |
41 ms |
64892 KB |
Output is correct |
25 |
Correct |
43 ms |
64896 KB |
Output is correct |
26 |
Correct |
38 ms |
64888 KB |
Output is correct |
27 |
Correct |
42 ms |
65016 KB |
Output is correct |
28 |
Correct |
38 ms |
64888 KB |
Output is correct |
29 |
Correct |
41 ms |
64888 KB |
Output is correct |
30 |
Correct |
39 ms |
64888 KB |
Output is correct |
31 |
Correct |
41 ms |
64888 KB |
Output is correct |
32 |
Correct |
38 ms |
64892 KB |
Output is correct |
33 |
Correct |
42 ms |
64896 KB |
Output is correct |
34 |
Correct |
39 ms |
64896 KB |
Output is correct |
35 |
Correct |
41 ms |
64888 KB |
Output is correct |
36 |
Correct |
38 ms |
64888 KB |
Output is correct |
37 |
Correct |
42 ms |
64896 KB |
Output is correct |
38 |
Correct |
39 ms |
64896 KB |
Output is correct |
39 |
Correct |
41 ms |
64888 KB |
Output is correct |
40 |
Correct |
38 ms |
64908 KB |
Output is correct |
41 |
Correct |
72 ms |
64896 KB |
Output is correct |
42 |
Correct |
51 ms |
64908 KB |
Output is correct |
43 |
Correct |
74 ms |
64888 KB |
Output is correct |
44 |
Correct |
54 ms |
64888 KB |
Output is correct |
45 |
Correct |
72 ms |
64896 KB |
Output is correct |
46 |
Correct |
52 ms |
64892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
64896 KB |
Output is correct |
2 |
Correct |
35 ms |
64888 KB |
Output is correct |
3 |
Correct |
36 ms |
64896 KB |
Output is correct |
4 |
Correct |
37 ms |
65024 KB |
Output is correct |
5 |
Correct |
37 ms |
64896 KB |
Output is correct |
6 |
Correct |
36 ms |
64896 KB |
Output is correct |
7 |
Correct |
36 ms |
64888 KB |
Output is correct |
8 |
Correct |
36 ms |
64888 KB |
Output is correct |
9 |
Correct |
36 ms |
64888 KB |
Output is correct |
10 |
Correct |
37 ms |
64888 KB |
Output is correct |
11 |
Correct |
36 ms |
64888 KB |
Output is correct |
12 |
Correct |
36 ms |
64888 KB |
Output is correct |
13 |
Correct |
37 ms |
64896 KB |
Output is correct |
14 |
Correct |
36 ms |
64888 KB |
Output is correct |
15 |
Correct |
36 ms |
64888 KB |
Output is correct |
16 |
Correct |
36 ms |
64896 KB |
Output is correct |
17 |
Correct |
36 ms |
64888 KB |
Output is correct |
18 |
Correct |
36 ms |
64888 KB |
Output is correct |
19 |
Correct |
36 ms |
64896 KB |
Output is correct |
20 |
Correct |
36 ms |
64888 KB |
Output is correct |
21 |
Correct |
36 ms |
64888 KB |
Output is correct |
22 |
Correct |
37 ms |
64888 KB |
Output is correct |
23 |
Correct |
36 ms |
64896 KB |
Output is correct |
24 |
Correct |
37 ms |
64888 KB |
Output is correct |
25 |
Correct |
41 ms |
64888 KB |
Output is correct |
26 |
Correct |
38 ms |
64888 KB |
Output is correct |
27 |
Correct |
36 ms |
64920 KB |
Output is correct |
28 |
Correct |
36 ms |
64888 KB |
Output is correct |
29 |
Correct |
36 ms |
64896 KB |
Output is correct |
30 |
Correct |
37 ms |
64896 KB |
Output is correct |
31 |
Correct |
36 ms |
64892 KB |
Output is correct |
32 |
Correct |
36 ms |
64888 KB |
Output is correct |
33 |
Correct |
36 ms |
64888 KB |
Output is correct |
34 |
Correct |
37 ms |
64888 KB |
Output is correct |
35 |
Correct |
36 ms |
64888 KB |
Output is correct |
36 |
Correct |
61 ms |
64888 KB |
Output is correct |
37 |
Correct |
50 ms |
64888 KB |
Output is correct |
38 |
Correct |
43 ms |
64896 KB |
Output is correct |
39 |
Correct |
49 ms |
64888 KB |
Output is correct |
40 |
Correct |
56 ms |
64896 KB |
Output is correct |
41 |
Correct |
43 ms |
64888 KB |
Output is correct |
42 |
Correct |
41 ms |
64892 KB |
Output is correct |
43 |
Correct |
43 ms |
64896 KB |
Output is correct |
44 |
Correct |
38 ms |
64888 KB |
Output is correct |
45 |
Correct |
42 ms |
65016 KB |
Output is correct |
46 |
Correct |
38 ms |
64888 KB |
Output is correct |
47 |
Correct |
41 ms |
64888 KB |
Output is correct |
48 |
Correct |
39 ms |
64888 KB |
Output is correct |
49 |
Correct |
41 ms |
64888 KB |
Output is correct |
50 |
Correct |
38 ms |
64892 KB |
Output is correct |
51 |
Correct |
42 ms |
64896 KB |
Output is correct |
52 |
Correct |
39 ms |
64896 KB |
Output is correct |
53 |
Correct |
41 ms |
64888 KB |
Output is correct |
54 |
Correct |
38 ms |
64888 KB |
Output is correct |
55 |
Correct |
42 ms |
64896 KB |
Output is correct |
56 |
Correct |
39 ms |
64896 KB |
Output is correct |
57 |
Correct |
41 ms |
64888 KB |
Output is correct |
58 |
Correct |
38 ms |
64908 KB |
Output is correct |
59 |
Correct |
72 ms |
64896 KB |
Output is correct |
60 |
Correct |
51 ms |
64908 KB |
Output is correct |
61 |
Correct |
74 ms |
64888 KB |
Output is correct |
62 |
Correct |
54 ms |
64888 KB |
Output is correct |
63 |
Correct |
72 ms |
64896 KB |
Output is correct |
64 |
Correct |
52 ms |
64892 KB |
Output is correct |
65 |
Correct |
62 ms |
64912 KB |
Output is correct |
66 |
Correct |
60 ms |
64888 KB |
Output is correct |
67 |
Correct |
59 ms |
64888 KB |
Output is correct |
68 |
Correct |
57 ms |
64888 KB |
Output is correct |
69 |
Correct |
64 ms |
64888 KB |
Output is correct |
70 |
Correct |
61 ms |
64892 KB |
Output is correct |
71 |
Correct |
59 ms |
64888 KB |
Output is correct |
72 |
Correct |
61 ms |
64896 KB |
Output is correct |
73 |
Correct |
56 ms |
64888 KB |
Output is correct |
74 |
Correct |
57 ms |
64888 KB |
Output is correct |
75 |
Correct |
57 ms |
64896 KB |
Output is correct |
76 |
Correct |
67 ms |
64888 KB |
Output is correct |
77 |
Correct |
64 ms |
64888 KB |
Output is correct |
78 |
Correct |
57 ms |
64888 KB |
Output is correct |
79 |
Correct |
57 ms |
65016 KB |
Output is correct |
80 |
Correct |
68 ms |
65024 KB |
Output is correct |
81 |
Correct |
54 ms |
64888 KB |
Output is correct |
82 |
Correct |
60 ms |
64892 KB |
Output is correct |
83 |
Correct |
64 ms |
64888 KB |
Output is correct |
84 |
Correct |
61 ms |
64888 KB |
Output is correct |
85 |
Correct |
61 ms |
64892 KB |
Output is correct |
86 |
Correct |
64 ms |
64888 KB |
Output is correct |
87 |
Correct |
58 ms |
64888 KB |
Output is correct |
88 |
Correct |
71 ms |
64888 KB |
Output is correct |
89 |
Correct |
65 ms |
64892 KB |
Output is correct |
90 |
Correct |
59 ms |
64944 KB |
Output is correct |
91 |
Correct |
70 ms |
64888 KB |
Output is correct |
92 |
Correct |
66 ms |
64896 KB |
Output is correct |
93 |
Correct |
64 ms |
64888 KB |
Output is correct |