#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 205;
int n, L, x[MN], t[MN], dp[MN][MN][MN][2], ans; //left, right, how many, left/right = min time
int d(int i, int j) {
i %= (n + 1), j %= (n + 1);
if (i < j) swap(i, j);
int p1 = L - x[i] + x[j], p2 = L - p1;
return min(p1, p2);
}
int rec(int l, int r, int k, int s) {
l %= (n + 1), r %= (n + 1);
//printf("%d %d %d %d\n", l, r, k, s);
if (dp[l][r][k][s] != -1) return dp[l][r][k][s];
int bst = 1e12;
if (!s && l > 0) {
bst = min(bst, rec(l + 1, r, k, 1) + d(l, r));
bst = min(bst, rec(l + 1, r, k, 0) + d(l, l + 1));
if (k) {
int v1 = rec(l + 1, r, k - 1, 1) + d(l, r);
if (v1 <= t[l]) bst = min(bst, v1);
int v2 = rec(l + 1, r, k - 1, 0) + d(l, l + 1);
if (v2 <= t[l]) bst = min(bst, v2);
}
}
if (s && r > 0) {
bst = min(bst, rec(l, r - 1, k, 0) + d(l, r));
bst = min(bst, rec(l, r - 1, k, 1) + d(r - 1, r));
if (k) {
int v1 = rec(l, r - 1, k - 1, 0) + d(l, r);
if (v1 <= t[r]) bst = min(bst, v1);
int v2 = rec(l, r - 1, k - 1, 1) + d(r - 1, r);
if (v2 <= t[r]) bst = min(bst, v2);
}
}
return dp[l][r][k][s] = bst;
}
int32_t main() {
boost();
cin >> n >> L;
for (int i = 1; i <= n; i++) cin >> x[i];
for (int i = 1; i <= n; i++) cin >> t[i];
memset(dp, -1, sizeof(dp));
dp[0][0][0][0] = dp[0][0][0][1] = dp[n + 1][0][0][0] = dp[n + 1][0][0][1] = 0;
for (int l = 0; l <= n; l++) {
int r = l - 1;
if (r < 0) r = n;
for (int k = 1; k <= n; k++) if (min(rec(l, r, k, 0), rec(l, r, k, 1)) < 1e12) ans = max(ans, k);
}
printf("%lld\n", ans);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
135208 KB |
Output is correct |
2 |
Correct |
48 ms |
135080 KB |
Output is correct |
3 |
Correct |
50 ms |
135160 KB |
Output is correct |
4 |
Correct |
50 ms |
135084 KB |
Output is correct |
5 |
Correct |
49 ms |
135116 KB |
Output is correct |
6 |
Correct |
49 ms |
135124 KB |
Output is correct |
7 |
Correct |
49 ms |
135116 KB |
Output is correct |
8 |
Correct |
49 ms |
135128 KB |
Output is correct |
9 |
Correct |
49 ms |
135172 KB |
Output is correct |
10 |
Correct |
51 ms |
135064 KB |
Output is correct |
11 |
Correct |
50 ms |
135056 KB |
Output is correct |
12 |
Correct |
50 ms |
135100 KB |
Output is correct |
13 |
Correct |
50 ms |
135096 KB |
Output is correct |
14 |
Correct |
50 ms |
135068 KB |
Output is correct |
15 |
Correct |
49 ms |
135104 KB |
Output is correct |
16 |
Correct |
49 ms |
135140 KB |
Output is correct |
17 |
Correct |
49 ms |
135168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
135208 KB |
Output is correct |
2 |
Correct |
48 ms |
135080 KB |
Output is correct |
3 |
Correct |
50 ms |
135160 KB |
Output is correct |
4 |
Correct |
50 ms |
135084 KB |
Output is correct |
5 |
Correct |
49 ms |
135116 KB |
Output is correct |
6 |
Correct |
49 ms |
135124 KB |
Output is correct |
7 |
Correct |
49 ms |
135116 KB |
Output is correct |
8 |
Correct |
49 ms |
135128 KB |
Output is correct |
9 |
Correct |
49 ms |
135172 KB |
Output is correct |
10 |
Correct |
51 ms |
135064 KB |
Output is correct |
11 |
Correct |
50 ms |
135056 KB |
Output is correct |
12 |
Correct |
50 ms |
135100 KB |
Output is correct |
13 |
Correct |
50 ms |
135096 KB |
Output is correct |
14 |
Correct |
50 ms |
135068 KB |
Output is correct |
15 |
Correct |
49 ms |
135104 KB |
Output is correct |
16 |
Correct |
49 ms |
135140 KB |
Output is correct |
17 |
Correct |
49 ms |
135168 KB |
Output is correct |
18 |
Correct |
50 ms |
135152 KB |
Output is correct |
19 |
Correct |
50 ms |
135116 KB |
Output is correct |
20 |
Correct |
51 ms |
135252 KB |
Output is correct |
21 |
Correct |
51 ms |
135068 KB |
Output is correct |
22 |
Correct |
55 ms |
135076 KB |
Output is correct |
23 |
Correct |
51 ms |
135128 KB |
Output is correct |
24 |
Correct |
51 ms |
135072 KB |
Output is correct |
25 |
Correct |
52 ms |
135116 KB |
Output is correct |
26 |
Correct |
50 ms |
135116 KB |
Output is correct |
27 |
Correct |
48 ms |
135076 KB |
Output is correct |
28 |
Correct |
49 ms |
135144 KB |
Output is correct |
29 |
Correct |
49 ms |
135116 KB |
Output is correct |
30 |
Correct |
51 ms |
135116 KB |
Output is correct |
31 |
Correct |
50 ms |
135128 KB |
Output is correct |
32 |
Correct |
49 ms |
135100 KB |
Output is correct |
33 |
Correct |
50 ms |
135140 KB |
Output is correct |
34 |
Correct |
55 ms |
135128 KB |
Output is correct |
35 |
Correct |
54 ms |
135108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
135208 KB |
Output is correct |
2 |
Correct |
48 ms |
135080 KB |
Output is correct |
3 |
Correct |
50 ms |
135160 KB |
Output is correct |
4 |
Correct |
50 ms |
135084 KB |
Output is correct |
5 |
Correct |
49 ms |
135116 KB |
Output is correct |
6 |
Correct |
49 ms |
135124 KB |
Output is correct |
7 |
Correct |
49 ms |
135116 KB |
Output is correct |
8 |
Correct |
49 ms |
135128 KB |
Output is correct |
9 |
Correct |
49 ms |
135172 KB |
Output is correct |
10 |
Correct |
51 ms |
135064 KB |
Output is correct |
11 |
Correct |
50 ms |
135056 KB |
Output is correct |
12 |
Correct |
50 ms |
135100 KB |
Output is correct |
13 |
Correct |
50 ms |
135096 KB |
Output is correct |
14 |
Correct |
50 ms |
135068 KB |
Output is correct |
15 |
Correct |
49 ms |
135104 KB |
Output is correct |
16 |
Correct |
49 ms |
135140 KB |
Output is correct |
17 |
Correct |
49 ms |
135168 KB |
Output is correct |
18 |
Correct |
490 ms |
135188 KB |
Output is correct |
19 |
Correct |
262 ms |
135184 KB |
Output is correct |
20 |
Correct |
130 ms |
135184 KB |
Output is correct |
21 |
Correct |
250 ms |
135176 KB |
Output is correct |
22 |
Correct |
346 ms |
135184 KB |
Output is correct |
23 |
Correct |
113 ms |
135120 KB |
Output is correct |
24 |
Correct |
96 ms |
135160 KB |
Output is correct |
25 |
Correct |
111 ms |
135064 KB |
Output is correct |
26 |
Correct |
65 ms |
135124 KB |
Output is correct |
27 |
Correct |
118 ms |
135096 KB |
Output is correct |
28 |
Correct |
90 ms |
135076 KB |
Output is correct |
29 |
Correct |
118 ms |
135112 KB |
Output is correct |
30 |
Correct |
97 ms |
135176 KB |
Output is correct |
31 |
Correct |
111 ms |
135096 KB |
Output is correct |
32 |
Correct |
75 ms |
135080 KB |
Output is correct |
33 |
Correct |
113 ms |
135180 KB |
Output is correct |
34 |
Correct |
64 ms |
135156 KB |
Output is correct |
35 |
Correct |
111 ms |
135100 KB |
Output is correct |
36 |
Correct |
69 ms |
135116 KB |
Output is correct |
37 |
Correct |
119 ms |
135120 KB |
Output is correct |
38 |
Correct |
77 ms |
135096 KB |
Output is correct |
39 |
Correct |
118 ms |
135088 KB |
Output is correct |
40 |
Correct |
80 ms |
135116 KB |
Output is correct |
41 |
Correct |
657 ms |
135244 KB |
Output is correct |
42 |
Correct |
379 ms |
135184 KB |
Output is correct |
43 |
Correct |
657 ms |
135180 KB |
Output is correct |
44 |
Correct |
376 ms |
135256 KB |
Output is correct |
45 |
Correct |
645 ms |
135188 KB |
Output is correct |
46 |
Correct |
384 ms |
135188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
135208 KB |
Output is correct |
2 |
Correct |
48 ms |
135080 KB |
Output is correct |
3 |
Correct |
50 ms |
135160 KB |
Output is correct |
4 |
Correct |
50 ms |
135084 KB |
Output is correct |
5 |
Correct |
49 ms |
135116 KB |
Output is correct |
6 |
Correct |
49 ms |
135124 KB |
Output is correct |
7 |
Correct |
49 ms |
135116 KB |
Output is correct |
8 |
Correct |
49 ms |
135128 KB |
Output is correct |
9 |
Correct |
49 ms |
135172 KB |
Output is correct |
10 |
Correct |
51 ms |
135064 KB |
Output is correct |
11 |
Correct |
50 ms |
135056 KB |
Output is correct |
12 |
Correct |
50 ms |
135100 KB |
Output is correct |
13 |
Correct |
50 ms |
135096 KB |
Output is correct |
14 |
Correct |
50 ms |
135068 KB |
Output is correct |
15 |
Correct |
49 ms |
135104 KB |
Output is correct |
16 |
Correct |
49 ms |
135140 KB |
Output is correct |
17 |
Correct |
49 ms |
135168 KB |
Output is correct |
18 |
Correct |
50 ms |
135152 KB |
Output is correct |
19 |
Correct |
50 ms |
135116 KB |
Output is correct |
20 |
Correct |
51 ms |
135252 KB |
Output is correct |
21 |
Correct |
51 ms |
135068 KB |
Output is correct |
22 |
Correct |
55 ms |
135076 KB |
Output is correct |
23 |
Correct |
51 ms |
135128 KB |
Output is correct |
24 |
Correct |
51 ms |
135072 KB |
Output is correct |
25 |
Correct |
52 ms |
135116 KB |
Output is correct |
26 |
Correct |
50 ms |
135116 KB |
Output is correct |
27 |
Correct |
48 ms |
135076 KB |
Output is correct |
28 |
Correct |
49 ms |
135144 KB |
Output is correct |
29 |
Correct |
49 ms |
135116 KB |
Output is correct |
30 |
Correct |
51 ms |
135116 KB |
Output is correct |
31 |
Correct |
50 ms |
135128 KB |
Output is correct |
32 |
Correct |
49 ms |
135100 KB |
Output is correct |
33 |
Correct |
50 ms |
135140 KB |
Output is correct |
34 |
Correct |
55 ms |
135128 KB |
Output is correct |
35 |
Correct |
54 ms |
135108 KB |
Output is correct |
36 |
Correct |
490 ms |
135188 KB |
Output is correct |
37 |
Correct |
262 ms |
135184 KB |
Output is correct |
38 |
Correct |
130 ms |
135184 KB |
Output is correct |
39 |
Correct |
250 ms |
135176 KB |
Output is correct |
40 |
Correct |
346 ms |
135184 KB |
Output is correct |
41 |
Correct |
113 ms |
135120 KB |
Output is correct |
42 |
Correct |
96 ms |
135160 KB |
Output is correct |
43 |
Correct |
111 ms |
135064 KB |
Output is correct |
44 |
Correct |
65 ms |
135124 KB |
Output is correct |
45 |
Correct |
118 ms |
135096 KB |
Output is correct |
46 |
Correct |
90 ms |
135076 KB |
Output is correct |
47 |
Correct |
118 ms |
135112 KB |
Output is correct |
48 |
Correct |
97 ms |
135176 KB |
Output is correct |
49 |
Correct |
111 ms |
135096 KB |
Output is correct |
50 |
Correct |
75 ms |
135080 KB |
Output is correct |
51 |
Correct |
113 ms |
135180 KB |
Output is correct |
52 |
Correct |
64 ms |
135156 KB |
Output is correct |
53 |
Correct |
111 ms |
135100 KB |
Output is correct |
54 |
Correct |
69 ms |
135116 KB |
Output is correct |
55 |
Correct |
119 ms |
135120 KB |
Output is correct |
56 |
Correct |
77 ms |
135096 KB |
Output is correct |
57 |
Correct |
118 ms |
135088 KB |
Output is correct |
58 |
Correct |
80 ms |
135116 KB |
Output is correct |
59 |
Correct |
657 ms |
135244 KB |
Output is correct |
60 |
Correct |
379 ms |
135184 KB |
Output is correct |
61 |
Correct |
657 ms |
135180 KB |
Output is correct |
62 |
Correct |
376 ms |
135256 KB |
Output is correct |
63 |
Correct |
645 ms |
135188 KB |
Output is correct |
64 |
Correct |
384 ms |
135188 KB |
Output is correct |
65 |
Correct |
574 ms |
135192 KB |
Output is correct |
66 |
Correct |
509 ms |
135084 KB |
Output is correct |
67 |
Correct |
480 ms |
135184 KB |
Output is correct |
68 |
Correct |
428 ms |
135208 KB |
Output is correct |
69 |
Correct |
562 ms |
135260 KB |
Output is correct |
70 |
Correct |
532 ms |
135116 KB |
Output is correct |
71 |
Correct |
530 ms |
135196 KB |
Output is correct |
72 |
Correct |
551 ms |
135244 KB |
Output is correct |
73 |
Correct |
493 ms |
135244 KB |
Output is correct |
74 |
Correct |
450 ms |
135188 KB |
Output is correct |
75 |
Correct |
516 ms |
135248 KB |
Output is correct |
76 |
Correct |
635 ms |
135200 KB |
Output is correct |
77 |
Correct |
610 ms |
135244 KB |
Output is correct |
78 |
Correct |
445 ms |
135244 KB |
Output is correct |
79 |
Correct |
454 ms |
135244 KB |
Output is correct |
80 |
Correct |
610 ms |
135192 KB |
Output is correct |
81 |
Correct |
465 ms |
135192 KB |
Output is correct |
82 |
Correct |
501 ms |
135196 KB |
Output is correct |
83 |
Correct |
640 ms |
135116 KB |
Output is correct |
84 |
Correct |
540 ms |
135192 KB |
Output is correct |
85 |
Correct |
590 ms |
135260 KB |
Output is correct |
86 |
Correct |
570 ms |
135192 KB |
Output is correct |
87 |
Correct |
518 ms |
135192 KB |
Output is correct |
88 |
Correct |
678 ms |
135192 KB |
Output is correct |
89 |
Correct |
660 ms |
135172 KB |
Output is correct |
90 |
Correct |
520 ms |
135200 KB |
Output is correct |
91 |
Correct |
676 ms |
135192 KB |
Output is correct |
92 |
Correct |
677 ms |
135200 KB |
Output is correct |
93 |
Correct |
642 ms |
135244 KB |
Output is correct |