#include "bits/stdc++.h"
using namespace std;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 203;
const int INF = 0x3f3f3f3f;
int a[N], t[N];
int dp[N][N][N][2];
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, p;
cin >> n >> p;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
cin >> t[i];
}
t[0] = -1;
memset(dp, INF, sizeof dp);
int ans = 0;
dp[0][0][0][0] = 0;
dp[0][0][0][1] = 0;
for (int c = 0; c <= n; ++c) {
for (int l = n, tc = 0; ; l = (l - 1 < 0 ? n : l - 1)) {
tc += l == n;
if (tc == 3) break;
for (int r = 0; r <= n; ++r) {
for (int il = 0; il < 2; ++il) {
if (dp[c][l][r][il] == INF) {
continue;
}
ans = max(ans, c);
int cur = il ? l : r;
int ct = dp[c][l][r][il];
//deb(c) deb(l) deb(r) deb(il) deb(ct) cout << '\n';
int nl = (l == 0 ? n : l - 1);
int nr = r + 1;
int ndl = (l == 0 ? a[cur] + p - a[n] : il ? a[cur] - a[l - 1] : a[cur] + p - a[l - 1]);
int ndr = (l > r && il ? p - a[cur] + a[r + 1] : a[r + 1] - a[cur]);
if (nl != r) {
if (ndl + ct <= t[nl]) {
dp[c + 1][nl][r][1] = min(dp[c + 1][nl][r][1], ct + ndl);
}
dp[c][nl][r][1] = min(dp[c][nl][r][1], ct + ndl);
}
if (nr <= n && nr != l) {
if (ndr + ct <= t[nr]) {
dp[c + 1][l][nr][0] = min(dp[c + 1][l][nr][0], ct + ndr);
}
dp[c][l][nr][0] = min(dp[c][l][nr][0], ct + ndr);
}
}
}
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
65880 KB |
Output is correct |
2 |
Correct |
8 ms |
65880 KB |
Output is correct |
3 |
Correct |
8 ms |
65884 KB |
Output is correct |
4 |
Correct |
8 ms |
65788 KB |
Output is correct |
5 |
Correct |
9 ms |
65884 KB |
Output is correct |
6 |
Correct |
8 ms |
65924 KB |
Output is correct |
7 |
Correct |
8 ms |
65764 KB |
Output is correct |
8 |
Correct |
8 ms |
65884 KB |
Output is correct |
9 |
Correct |
8 ms |
65884 KB |
Output is correct |
10 |
Correct |
8 ms |
65708 KB |
Output is correct |
11 |
Correct |
7 ms |
65696 KB |
Output is correct |
12 |
Correct |
8 ms |
65884 KB |
Output is correct |
13 |
Correct |
8 ms |
65700 KB |
Output is correct |
14 |
Correct |
8 ms |
65884 KB |
Output is correct |
15 |
Correct |
8 ms |
65884 KB |
Output is correct |
16 |
Correct |
8 ms |
65752 KB |
Output is correct |
17 |
Correct |
8 ms |
65880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
65880 KB |
Output is correct |
2 |
Correct |
8 ms |
65880 KB |
Output is correct |
3 |
Correct |
8 ms |
65884 KB |
Output is correct |
4 |
Correct |
8 ms |
65788 KB |
Output is correct |
5 |
Correct |
9 ms |
65884 KB |
Output is correct |
6 |
Correct |
8 ms |
65924 KB |
Output is correct |
7 |
Correct |
8 ms |
65764 KB |
Output is correct |
8 |
Correct |
8 ms |
65884 KB |
Output is correct |
9 |
Correct |
8 ms |
65884 KB |
Output is correct |
10 |
Correct |
8 ms |
65708 KB |
Output is correct |
11 |
Correct |
7 ms |
65696 KB |
Output is correct |
12 |
Correct |
8 ms |
65884 KB |
Output is correct |
13 |
Correct |
8 ms |
65700 KB |
Output is correct |
14 |
Correct |
8 ms |
65884 KB |
Output is correct |
15 |
Correct |
8 ms |
65884 KB |
Output is correct |
16 |
Correct |
8 ms |
65752 KB |
Output is correct |
17 |
Correct |
8 ms |
65880 KB |
Output is correct |
18 |
Correct |
8 ms |
66136 KB |
Output is correct |
19 |
Correct |
8 ms |
65740 KB |
Output is correct |
20 |
Correct |
8 ms |
65792 KB |
Output is correct |
21 |
Correct |
9 ms |
65884 KB |
Output is correct |
22 |
Correct |
8 ms |
65884 KB |
Output is correct |
23 |
Correct |
9 ms |
65884 KB |
Output is correct |
24 |
Correct |
8 ms |
65884 KB |
Output is correct |
25 |
Correct |
8 ms |
65884 KB |
Output is correct |
26 |
Correct |
8 ms |
65884 KB |
Output is correct |
27 |
Correct |
8 ms |
65756 KB |
Output is correct |
28 |
Correct |
9 ms |
66140 KB |
Output is correct |
29 |
Correct |
8 ms |
65880 KB |
Output is correct |
30 |
Correct |
8 ms |
65784 KB |
Output is correct |
31 |
Correct |
8 ms |
65884 KB |
Output is correct |
32 |
Correct |
8 ms |
65880 KB |
Output is correct |
33 |
Correct |
9 ms |
65732 KB |
Output is correct |
34 |
Correct |
8 ms |
65884 KB |
Output is correct |
35 |
Correct |
8 ms |
66136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
65880 KB |
Output is correct |
2 |
Correct |
8 ms |
65880 KB |
Output is correct |
3 |
Correct |
8 ms |
65884 KB |
Output is correct |
4 |
Correct |
8 ms |
65788 KB |
Output is correct |
5 |
Correct |
9 ms |
65884 KB |
Output is correct |
6 |
Correct |
8 ms |
65924 KB |
Output is correct |
7 |
Correct |
8 ms |
65764 KB |
Output is correct |
8 |
Correct |
8 ms |
65884 KB |
Output is correct |
9 |
Correct |
8 ms |
65884 KB |
Output is correct |
10 |
Correct |
8 ms |
65708 KB |
Output is correct |
11 |
Correct |
7 ms |
65696 KB |
Output is correct |
12 |
Correct |
8 ms |
65884 KB |
Output is correct |
13 |
Correct |
8 ms |
65700 KB |
Output is correct |
14 |
Correct |
8 ms |
65884 KB |
Output is correct |
15 |
Correct |
8 ms |
65884 KB |
Output is correct |
16 |
Correct |
8 ms |
65752 KB |
Output is correct |
17 |
Correct |
8 ms |
65880 KB |
Output is correct |
18 |
Correct |
54 ms |
65884 KB |
Output is correct |
19 |
Correct |
31 ms |
65884 KB |
Output is correct |
20 |
Correct |
18 ms |
66140 KB |
Output is correct |
21 |
Correct |
29 ms |
65884 KB |
Output is correct |
22 |
Correct |
39 ms |
65884 KB |
Output is correct |
23 |
Correct |
17 ms |
65884 KB |
Output is correct |
24 |
Correct |
12 ms |
65880 KB |
Output is correct |
25 |
Correct |
19 ms |
65932 KB |
Output is correct |
26 |
Correct |
9 ms |
66136 KB |
Output is correct |
27 |
Correct |
19 ms |
65940 KB |
Output is correct |
28 |
Correct |
13 ms |
65884 KB |
Output is correct |
29 |
Correct |
17 ms |
65892 KB |
Output is correct |
30 |
Correct |
12 ms |
65880 KB |
Output is correct |
31 |
Correct |
17 ms |
65884 KB |
Output is correct |
32 |
Correct |
11 ms |
65880 KB |
Output is correct |
33 |
Correct |
16 ms |
65884 KB |
Output is correct |
34 |
Correct |
9 ms |
65928 KB |
Output is correct |
35 |
Correct |
14 ms |
65720 KB |
Output is correct |
36 |
Correct |
10 ms |
65892 KB |
Output is correct |
37 |
Correct |
17 ms |
65932 KB |
Output is correct |
38 |
Correct |
14 ms |
65884 KB |
Output is correct |
39 |
Correct |
14 ms |
65944 KB |
Output is correct |
40 |
Correct |
10 ms |
65884 KB |
Output is correct |
41 |
Correct |
84 ms |
65928 KB |
Output is correct |
42 |
Correct |
29 ms |
65928 KB |
Output is correct |
43 |
Correct |
101 ms |
65884 KB |
Output is correct |
44 |
Correct |
29 ms |
65884 KB |
Output is correct |
45 |
Correct |
85 ms |
65912 KB |
Output is correct |
46 |
Correct |
29 ms |
65880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
65880 KB |
Output is correct |
2 |
Correct |
8 ms |
65880 KB |
Output is correct |
3 |
Correct |
8 ms |
65884 KB |
Output is correct |
4 |
Correct |
8 ms |
65788 KB |
Output is correct |
5 |
Correct |
9 ms |
65884 KB |
Output is correct |
6 |
Correct |
8 ms |
65924 KB |
Output is correct |
7 |
Correct |
8 ms |
65764 KB |
Output is correct |
8 |
Correct |
8 ms |
65884 KB |
Output is correct |
9 |
Correct |
8 ms |
65884 KB |
Output is correct |
10 |
Correct |
8 ms |
65708 KB |
Output is correct |
11 |
Correct |
7 ms |
65696 KB |
Output is correct |
12 |
Correct |
8 ms |
65884 KB |
Output is correct |
13 |
Correct |
8 ms |
65700 KB |
Output is correct |
14 |
Correct |
8 ms |
65884 KB |
Output is correct |
15 |
Correct |
8 ms |
65884 KB |
Output is correct |
16 |
Correct |
8 ms |
65752 KB |
Output is correct |
17 |
Correct |
8 ms |
65880 KB |
Output is correct |
18 |
Correct |
8 ms |
66136 KB |
Output is correct |
19 |
Correct |
8 ms |
65740 KB |
Output is correct |
20 |
Correct |
8 ms |
65792 KB |
Output is correct |
21 |
Correct |
9 ms |
65884 KB |
Output is correct |
22 |
Correct |
8 ms |
65884 KB |
Output is correct |
23 |
Correct |
9 ms |
65884 KB |
Output is correct |
24 |
Correct |
8 ms |
65884 KB |
Output is correct |
25 |
Correct |
8 ms |
65884 KB |
Output is correct |
26 |
Correct |
8 ms |
65884 KB |
Output is correct |
27 |
Correct |
8 ms |
65756 KB |
Output is correct |
28 |
Correct |
9 ms |
66140 KB |
Output is correct |
29 |
Correct |
8 ms |
65880 KB |
Output is correct |
30 |
Correct |
8 ms |
65784 KB |
Output is correct |
31 |
Correct |
8 ms |
65884 KB |
Output is correct |
32 |
Correct |
8 ms |
65880 KB |
Output is correct |
33 |
Correct |
9 ms |
65732 KB |
Output is correct |
34 |
Correct |
8 ms |
65884 KB |
Output is correct |
35 |
Correct |
8 ms |
66136 KB |
Output is correct |
36 |
Correct |
54 ms |
65884 KB |
Output is correct |
37 |
Correct |
31 ms |
65884 KB |
Output is correct |
38 |
Correct |
18 ms |
66140 KB |
Output is correct |
39 |
Correct |
29 ms |
65884 KB |
Output is correct |
40 |
Correct |
39 ms |
65884 KB |
Output is correct |
41 |
Correct |
17 ms |
65884 KB |
Output is correct |
42 |
Correct |
12 ms |
65880 KB |
Output is correct |
43 |
Correct |
19 ms |
65932 KB |
Output is correct |
44 |
Correct |
9 ms |
66136 KB |
Output is correct |
45 |
Correct |
19 ms |
65940 KB |
Output is correct |
46 |
Correct |
13 ms |
65884 KB |
Output is correct |
47 |
Correct |
17 ms |
65892 KB |
Output is correct |
48 |
Correct |
12 ms |
65880 KB |
Output is correct |
49 |
Correct |
17 ms |
65884 KB |
Output is correct |
50 |
Correct |
11 ms |
65880 KB |
Output is correct |
51 |
Correct |
16 ms |
65884 KB |
Output is correct |
52 |
Correct |
9 ms |
65928 KB |
Output is correct |
53 |
Correct |
14 ms |
65720 KB |
Output is correct |
54 |
Correct |
10 ms |
65892 KB |
Output is correct |
55 |
Correct |
17 ms |
65932 KB |
Output is correct |
56 |
Correct |
14 ms |
65884 KB |
Output is correct |
57 |
Correct |
14 ms |
65944 KB |
Output is correct |
58 |
Correct |
10 ms |
65884 KB |
Output is correct |
59 |
Correct |
84 ms |
65928 KB |
Output is correct |
60 |
Correct |
29 ms |
65928 KB |
Output is correct |
61 |
Correct |
101 ms |
65884 KB |
Output is correct |
62 |
Correct |
29 ms |
65884 KB |
Output is correct |
63 |
Correct |
85 ms |
65912 KB |
Output is correct |
64 |
Correct |
29 ms |
65880 KB |
Output is correct |
65 |
Correct |
54 ms |
65884 KB |
Output is correct |
66 |
Correct |
50 ms |
65884 KB |
Output is correct |
67 |
Correct |
45 ms |
65920 KB |
Output is correct |
68 |
Correct |
41 ms |
65880 KB |
Output is correct |
69 |
Correct |
66 ms |
65880 KB |
Output is correct |
70 |
Correct |
62 ms |
65884 KB |
Output is correct |
71 |
Correct |
44 ms |
65884 KB |
Output is correct |
72 |
Correct |
64 ms |
65884 KB |
Output is correct |
73 |
Correct |
37 ms |
65912 KB |
Output is correct |
74 |
Correct |
55 ms |
65884 KB |
Output is correct |
75 |
Correct |
41 ms |
65940 KB |
Output is correct |
76 |
Correct |
71 ms |
65912 KB |
Output is correct |
77 |
Correct |
48 ms |
66080 KB |
Output is correct |
78 |
Correct |
58 ms |
65916 KB |
Output is correct |
79 |
Correct |
40 ms |
65880 KB |
Output is correct |
80 |
Correct |
69 ms |
65884 KB |
Output is correct |
81 |
Correct |
41 ms |
65884 KB |
Output is correct |
82 |
Correct |
51 ms |
66016 KB |
Output is correct |
83 |
Correct |
58 ms |
65884 KB |
Output is correct |
84 |
Correct |
48 ms |
65884 KB |
Output is correct |
85 |
Correct |
42 ms |
65884 KB |
Output is correct |
86 |
Correct |
52 ms |
65884 KB |
Output is correct |
87 |
Correct |
43 ms |
65884 KB |
Output is correct |
88 |
Correct |
84 ms |
65916 KB |
Output is correct |
89 |
Correct |
66 ms |
65916 KB |
Output is correct |
90 |
Correct |
38 ms |
65884 KB |
Output is correct |
91 |
Correct |
78 ms |
65688 KB |
Output is correct |
92 |
Correct |
66 ms |
65920 KB |
Output is correct |
93 |
Correct |
46 ms |
65916 KB |
Output is correct |