#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline void fastio() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
}
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll n, l, ans;
ll arr[202], t[202];
ll cdp[202][202][202], rdp[202][202][202]; // 시계, 반시계, 개수
int main() {
fastio();
cin >> n >> l;
for (ll i = 1; i <= n; i++) {
cin >> arr[i];
}
arr[n + 1] = l;
for (ll i = 1; i <= n; i++) {
cin >> t[i];
}
memset(cdp, 0x3f, sizeof(cdp));
memset(rdp, 0x3f, sizeof(rdp));
for (ll i = 0; i <= n; i++) {
for (ll j = n + 1; j > i; j--) {
for (ll k = 0; k <= n; k++) {
if (i == 0 and j == n + 1 and k == 0) {
cdp[i][j][k] = rdp[i][j][k] = 0;
}
ll& x = cdp[i][j][k];
if (i > 0) {
ll ct = arr[i] - arr[i - 1], rt = l - arr[j] + arr[i];
if (k > 0 and cdp[i - 1][j][k - 1] + ct <= t[i]) x = min(x, cdp[i - 1][j][k - 1] + ct);
if (cdp[i - 1][j][k - 1] + ct > t[i]) x = min(x, cdp[i - 1][j][k] + ct);
if (k > 0 and rdp[i - 1][j][k - 1] + rt <= t[i]) x = min(x, rdp[i - 1][j][k - 1] + rt);
if (rdp[i - 1][j][k - 1] + rt > t[i]) x = min(x, rdp[i - 1][j][k] + rt);
}
ll& y = rdp[i][j][k];
if (j <= n) {
ll rt = arr[j + 1] - arr[j], ct = l - arr[j] + arr[i];
if (k > 0 and rdp[i][j + 1][k - 1] + rt <= t[j]) y = min(y, rdp[i][j + 1][k - 1] + rt);
if (rdp[i][j + 1][k - 1] + rt > t[j]) y = min(y, rdp[i][j + 1][k] + rt);
if (k > 0 and cdp[i][j + 1][k - 1] + ct <= t[j]) y = min(y, cdp[i][j + 1][k - 1] + ct);
if (cdp[i][j + 1][k - 1] + ct > t[j]) y = min(y, cdp[i][j + 1][k] + ct);
}
if (ans < k) {
if (x != INF) ans = k;
if (y != INF) ans = k;
}
}
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
129372 KB |
Output is correct |
2 |
Correct |
16 ms |
129428 KB |
Output is correct |
3 |
Correct |
17 ms |
129460 KB |
Output is correct |
4 |
Correct |
18 ms |
129368 KB |
Output is correct |
5 |
Correct |
18 ms |
129372 KB |
Output is correct |
6 |
Correct |
18 ms |
129264 KB |
Output is correct |
7 |
Correct |
16 ms |
129624 KB |
Output is correct |
8 |
Correct |
19 ms |
129432 KB |
Output is correct |
9 |
Correct |
16 ms |
129368 KB |
Output is correct |
10 |
Correct |
17 ms |
129372 KB |
Output is correct |
11 |
Correct |
17 ms |
129300 KB |
Output is correct |
12 |
Correct |
17 ms |
129372 KB |
Output is correct |
13 |
Correct |
17 ms |
129492 KB |
Output is correct |
14 |
Correct |
16 ms |
129460 KB |
Output is correct |
15 |
Correct |
16 ms |
129372 KB |
Output is correct |
16 |
Correct |
17 ms |
129372 KB |
Output is correct |
17 |
Correct |
17 ms |
129264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
129372 KB |
Output is correct |
2 |
Correct |
16 ms |
129428 KB |
Output is correct |
3 |
Correct |
17 ms |
129460 KB |
Output is correct |
4 |
Correct |
18 ms |
129368 KB |
Output is correct |
5 |
Correct |
18 ms |
129372 KB |
Output is correct |
6 |
Correct |
18 ms |
129264 KB |
Output is correct |
7 |
Correct |
16 ms |
129624 KB |
Output is correct |
8 |
Correct |
19 ms |
129432 KB |
Output is correct |
9 |
Correct |
16 ms |
129368 KB |
Output is correct |
10 |
Correct |
17 ms |
129372 KB |
Output is correct |
11 |
Correct |
17 ms |
129300 KB |
Output is correct |
12 |
Correct |
17 ms |
129372 KB |
Output is correct |
13 |
Correct |
17 ms |
129492 KB |
Output is correct |
14 |
Correct |
16 ms |
129460 KB |
Output is correct |
15 |
Correct |
16 ms |
129372 KB |
Output is correct |
16 |
Correct |
17 ms |
129372 KB |
Output is correct |
17 |
Correct |
17 ms |
129264 KB |
Output is correct |
18 |
Correct |
17 ms |
129336 KB |
Output is correct |
19 |
Correct |
16 ms |
129364 KB |
Output is correct |
20 |
Correct |
18 ms |
129368 KB |
Output is correct |
21 |
Correct |
17 ms |
129372 KB |
Output is correct |
22 |
Correct |
19 ms |
129372 KB |
Output is correct |
23 |
Correct |
19 ms |
129408 KB |
Output is correct |
24 |
Correct |
17 ms |
129252 KB |
Output is correct |
25 |
Correct |
18 ms |
129488 KB |
Output is correct |
26 |
Correct |
20 ms |
129368 KB |
Output is correct |
27 |
Correct |
17 ms |
129372 KB |
Output is correct |
28 |
Correct |
16 ms |
129372 KB |
Output is correct |
29 |
Correct |
18 ms |
129452 KB |
Output is correct |
30 |
Correct |
17 ms |
129372 KB |
Output is correct |
31 |
Correct |
17 ms |
129424 KB |
Output is correct |
32 |
Correct |
17 ms |
129372 KB |
Output is correct |
33 |
Correct |
17 ms |
129372 KB |
Output is correct |
34 |
Correct |
17 ms |
129360 KB |
Output is correct |
35 |
Correct |
18 ms |
129308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
129372 KB |
Output is correct |
2 |
Correct |
16 ms |
129428 KB |
Output is correct |
3 |
Correct |
17 ms |
129460 KB |
Output is correct |
4 |
Correct |
18 ms |
129368 KB |
Output is correct |
5 |
Correct |
18 ms |
129372 KB |
Output is correct |
6 |
Correct |
18 ms |
129264 KB |
Output is correct |
7 |
Correct |
16 ms |
129624 KB |
Output is correct |
8 |
Correct |
19 ms |
129432 KB |
Output is correct |
9 |
Correct |
16 ms |
129368 KB |
Output is correct |
10 |
Correct |
17 ms |
129372 KB |
Output is correct |
11 |
Correct |
17 ms |
129300 KB |
Output is correct |
12 |
Correct |
17 ms |
129372 KB |
Output is correct |
13 |
Correct |
17 ms |
129492 KB |
Output is correct |
14 |
Correct |
16 ms |
129460 KB |
Output is correct |
15 |
Correct |
16 ms |
129372 KB |
Output is correct |
16 |
Correct |
17 ms |
129372 KB |
Output is correct |
17 |
Correct |
17 ms |
129264 KB |
Output is correct |
18 |
Correct |
37 ms |
129364 KB |
Output is correct |
19 |
Correct |
28 ms |
129372 KB |
Output is correct |
20 |
Correct |
21 ms |
129372 KB |
Output is correct |
21 |
Correct |
26 ms |
129420 KB |
Output is correct |
22 |
Correct |
30 ms |
129496 KB |
Output is correct |
23 |
Correct |
19 ms |
129368 KB |
Output is correct |
24 |
Correct |
19 ms |
129364 KB |
Output is correct |
25 |
Correct |
21 ms |
129372 KB |
Output is correct |
26 |
Correct |
17 ms |
129512 KB |
Output is correct |
27 |
Correct |
21 ms |
129372 KB |
Output is correct |
28 |
Correct |
19 ms |
129368 KB |
Output is correct |
29 |
Correct |
20 ms |
129464 KB |
Output is correct |
30 |
Correct |
19 ms |
129372 KB |
Output is correct |
31 |
Correct |
19 ms |
129368 KB |
Output is correct |
32 |
Correct |
18 ms |
129256 KB |
Output is correct |
33 |
Correct |
21 ms |
129500 KB |
Output is correct |
34 |
Correct |
17 ms |
129252 KB |
Output is correct |
35 |
Correct |
19 ms |
129372 KB |
Output is correct |
36 |
Correct |
18 ms |
129372 KB |
Output is correct |
37 |
Correct |
20 ms |
129372 KB |
Output is correct |
38 |
Correct |
18 ms |
129372 KB |
Output is correct |
39 |
Correct |
21 ms |
129368 KB |
Output is correct |
40 |
Correct |
18 ms |
129372 KB |
Output is correct |
41 |
Correct |
41 ms |
129372 KB |
Output is correct |
42 |
Correct |
33 ms |
129372 KB |
Output is correct |
43 |
Correct |
43 ms |
129372 KB |
Output is correct |
44 |
Correct |
32 ms |
129372 KB |
Output is correct |
45 |
Correct |
39 ms |
129372 KB |
Output is correct |
46 |
Correct |
32 ms |
129368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
129372 KB |
Output is correct |
2 |
Correct |
16 ms |
129428 KB |
Output is correct |
3 |
Correct |
17 ms |
129460 KB |
Output is correct |
4 |
Correct |
18 ms |
129368 KB |
Output is correct |
5 |
Correct |
18 ms |
129372 KB |
Output is correct |
6 |
Correct |
18 ms |
129264 KB |
Output is correct |
7 |
Correct |
16 ms |
129624 KB |
Output is correct |
8 |
Correct |
19 ms |
129432 KB |
Output is correct |
9 |
Correct |
16 ms |
129368 KB |
Output is correct |
10 |
Correct |
17 ms |
129372 KB |
Output is correct |
11 |
Correct |
17 ms |
129300 KB |
Output is correct |
12 |
Correct |
17 ms |
129372 KB |
Output is correct |
13 |
Correct |
17 ms |
129492 KB |
Output is correct |
14 |
Correct |
16 ms |
129460 KB |
Output is correct |
15 |
Correct |
16 ms |
129372 KB |
Output is correct |
16 |
Correct |
17 ms |
129372 KB |
Output is correct |
17 |
Correct |
17 ms |
129264 KB |
Output is correct |
18 |
Correct |
17 ms |
129336 KB |
Output is correct |
19 |
Correct |
16 ms |
129364 KB |
Output is correct |
20 |
Correct |
18 ms |
129368 KB |
Output is correct |
21 |
Correct |
17 ms |
129372 KB |
Output is correct |
22 |
Correct |
19 ms |
129372 KB |
Output is correct |
23 |
Correct |
19 ms |
129408 KB |
Output is correct |
24 |
Correct |
17 ms |
129252 KB |
Output is correct |
25 |
Correct |
18 ms |
129488 KB |
Output is correct |
26 |
Correct |
20 ms |
129368 KB |
Output is correct |
27 |
Correct |
17 ms |
129372 KB |
Output is correct |
28 |
Correct |
16 ms |
129372 KB |
Output is correct |
29 |
Correct |
18 ms |
129452 KB |
Output is correct |
30 |
Correct |
17 ms |
129372 KB |
Output is correct |
31 |
Correct |
17 ms |
129424 KB |
Output is correct |
32 |
Correct |
17 ms |
129372 KB |
Output is correct |
33 |
Correct |
17 ms |
129372 KB |
Output is correct |
34 |
Correct |
17 ms |
129360 KB |
Output is correct |
35 |
Correct |
18 ms |
129308 KB |
Output is correct |
36 |
Correct |
37 ms |
129364 KB |
Output is correct |
37 |
Correct |
28 ms |
129372 KB |
Output is correct |
38 |
Correct |
21 ms |
129372 KB |
Output is correct |
39 |
Correct |
26 ms |
129420 KB |
Output is correct |
40 |
Correct |
30 ms |
129496 KB |
Output is correct |
41 |
Correct |
19 ms |
129368 KB |
Output is correct |
42 |
Correct |
19 ms |
129364 KB |
Output is correct |
43 |
Correct |
21 ms |
129372 KB |
Output is correct |
44 |
Correct |
17 ms |
129512 KB |
Output is correct |
45 |
Correct |
21 ms |
129372 KB |
Output is correct |
46 |
Correct |
19 ms |
129368 KB |
Output is correct |
47 |
Correct |
20 ms |
129464 KB |
Output is correct |
48 |
Correct |
19 ms |
129372 KB |
Output is correct |
49 |
Correct |
19 ms |
129368 KB |
Output is correct |
50 |
Correct |
18 ms |
129256 KB |
Output is correct |
51 |
Correct |
21 ms |
129500 KB |
Output is correct |
52 |
Correct |
17 ms |
129252 KB |
Output is correct |
53 |
Correct |
19 ms |
129372 KB |
Output is correct |
54 |
Correct |
18 ms |
129372 KB |
Output is correct |
55 |
Correct |
20 ms |
129372 KB |
Output is correct |
56 |
Correct |
18 ms |
129372 KB |
Output is correct |
57 |
Correct |
21 ms |
129368 KB |
Output is correct |
58 |
Correct |
18 ms |
129372 KB |
Output is correct |
59 |
Correct |
41 ms |
129372 KB |
Output is correct |
60 |
Correct |
33 ms |
129372 KB |
Output is correct |
61 |
Correct |
43 ms |
129372 KB |
Output is correct |
62 |
Correct |
32 ms |
129372 KB |
Output is correct |
63 |
Correct |
39 ms |
129372 KB |
Output is correct |
64 |
Correct |
32 ms |
129368 KB |
Output is correct |
65 |
Correct |
39 ms |
129368 KB |
Output is correct |
66 |
Correct |
37 ms |
129372 KB |
Output is correct |
67 |
Correct |
35 ms |
129260 KB |
Output is correct |
68 |
Correct |
35 ms |
129624 KB |
Output is correct |
69 |
Correct |
39 ms |
129368 KB |
Output is correct |
70 |
Correct |
35 ms |
129372 KB |
Output is correct |
71 |
Correct |
38 ms |
129372 KB |
Output is correct |
72 |
Correct |
37 ms |
129360 KB |
Output is correct |
73 |
Correct |
36 ms |
129480 KB |
Output is correct |
74 |
Correct |
40 ms |
129372 KB |
Output is correct |
75 |
Correct |
38 ms |
129368 KB |
Output is correct |
76 |
Correct |
40 ms |
129404 KB |
Output is correct |
77 |
Correct |
42 ms |
129372 KB |
Output is correct |
78 |
Correct |
34 ms |
129372 KB |
Output is correct |
79 |
Correct |
36 ms |
129416 KB |
Output is correct |
80 |
Correct |
39 ms |
129360 KB |
Output is correct |
81 |
Correct |
34 ms |
129368 KB |
Output is correct |
82 |
Correct |
37 ms |
129372 KB |
Output is correct |
83 |
Correct |
43 ms |
129476 KB |
Output is correct |
84 |
Correct |
37 ms |
129368 KB |
Output is correct |
85 |
Correct |
41 ms |
129372 KB |
Output is correct |
86 |
Correct |
42 ms |
129372 KB |
Output is correct |
87 |
Correct |
36 ms |
129368 KB |
Output is correct |
88 |
Correct |
37 ms |
129372 KB |
Output is correct |
89 |
Correct |
37 ms |
129260 KB |
Output is correct |
90 |
Correct |
34 ms |
129372 KB |
Output is correct |
91 |
Correct |
63 ms |
129372 KB |
Output is correct |
92 |
Correct |
44 ms |
129464 KB |
Output is correct |
93 |
Correct |
46 ms |
129480 KB |
Output is correct |