#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 210;
ll f[N][N][N][2];
ll x[N], t[N];
void minimize(ll &a, ll b) {
if (a > b)
a = b;
}
ll n, l;
ll dis(ll a, ll b) {
return min(abs(a - b), l - abs(a - b));
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
mem(f, 0x3f);
cin >> n >> l;
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= n + 1; j++) {
for (int k = 0; k <= n + 1; k++) {
f[i][j][k][0] = f[i][j][k][1] = 1e15;
}
}
}
for (int i = 1; i <= n; i++)
cin >> x[i];
for (int i = 1; i <= n; i++)
cin >> t[i];
x[0] = 0;
x[n + 1] = l;
t[0] = -1;
t[n + 1] = -1;
f[0][0][n + 1][0] = 0;
f[0][0][n + 1][1] = 0;
int ans = 0;
for (int c = 0; c <= n; c++) {
for (int i = 0; i <= n + 1; i++) {
for (int j = n + 1; j > i; j--) {
if (i) {
if (c) {
ll ti = min(f[c - 1][i - 1][j][0] + dis(x[i - 1], x[i]), f[c - 1][i - 1][j][1] + dis(x[j], x[i]));
if (ti <= t[i])
minimize(f[c][i][j][0], ti);
}
minimize(f[c][i][j][0], min(f[c][i - 1][j][0] + dis(x[i - 1], x[i]), f[c][i - 1][j][1] + dis(x[j], x[i])));
}
if (j != n + 1) {
if (c) {
ll ti = min(f[c - 1][i][j + 1][1] + dis(x[j + 1], x[j]), f[c - 1][i][j + 1][0] + dis(x[j], x[i]));
if (ti <= t[j])
minimize(f[c][i][j][1], ti);
}
minimize(f[c][i][j][1], min(f[c][i][j + 1][1] + dis(x[j + 1], x[j]), f[c][i][j + 1][0] + dis(x[j], x[i])));
}
if (min(f[c][i][i][0], f[c][i][j][1]) < 1e14)
ans = max(ans, c);
}
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
145236 KB |
Output is correct |
2 |
Correct |
45 ms |
145396 KB |
Output is correct |
3 |
Correct |
45 ms |
145232 KB |
Output is correct |
4 |
Correct |
45 ms |
145232 KB |
Output is correct |
5 |
Correct |
46 ms |
145240 KB |
Output is correct |
6 |
Correct |
47 ms |
145236 KB |
Output is correct |
7 |
Correct |
47 ms |
145188 KB |
Output is correct |
8 |
Correct |
46 ms |
145236 KB |
Output is correct |
9 |
Correct |
46 ms |
145208 KB |
Output is correct |
10 |
Correct |
48 ms |
145640 KB |
Output is correct |
11 |
Correct |
46 ms |
145232 KB |
Output is correct |
12 |
Correct |
45 ms |
145488 KB |
Output is correct |
13 |
Correct |
45 ms |
145388 KB |
Output is correct |
14 |
Correct |
46 ms |
145232 KB |
Output is correct |
15 |
Correct |
45 ms |
145240 KB |
Output is correct |
16 |
Correct |
47 ms |
145228 KB |
Output is correct |
17 |
Correct |
46 ms |
145232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
145236 KB |
Output is correct |
2 |
Correct |
45 ms |
145396 KB |
Output is correct |
3 |
Correct |
45 ms |
145232 KB |
Output is correct |
4 |
Correct |
45 ms |
145232 KB |
Output is correct |
5 |
Correct |
46 ms |
145240 KB |
Output is correct |
6 |
Correct |
47 ms |
145236 KB |
Output is correct |
7 |
Correct |
47 ms |
145188 KB |
Output is correct |
8 |
Correct |
46 ms |
145236 KB |
Output is correct |
9 |
Correct |
46 ms |
145208 KB |
Output is correct |
10 |
Correct |
48 ms |
145640 KB |
Output is correct |
11 |
Correct |
46 ms |
145232 KB |
Output is correct |
12 |
Correct |
45 ms |
145488 KB |
Output is correct |
13 |
Correct |
45 ms |
145388 KB |
Output is correct |
14 |
Correct |
46 ms |
145232 KB |
Output is correct |
15 |
Correct |
45 ms |
145240 KB |
Output is correct |
16 |
Correct |
47 ms |
145228 KB |
Output is correct |
17 |
Correct |
46 ms |
145232 KB |
Output is correct |
18 |
Correct |
45 ms |
145232 KB |
Output is correct |
19 |
Correct |
46 ms |
145232 KB |
Output is correct |
20 |
Correct |
47 ms |
145232 KB |
Output is correct |
21 |
Correct |
46 ms |
145232 KB |
Output is correct |
22 |
Correct |
47 ms |
145236 KB |
Output is correct |
23 |
Correct |
47 ms |
145372 KB |
Output is correct |
24 |
Correct |
53 ms |
145236 KB |
Output is correct |
25 |
Correct |
48 ms |
145424 KB |
Output is correct |
26 |
Correct |
46 ms |
145232 KB |
Output is correct |
27 |
Correct |
46 ms |
145232 KB |
Output is correct |
28 |
Correct |
47 ms |
145236 KB |
Output is correct |
29 |
Correct |
47 ms |
145188 KB |
Output is correct |
30 |
Correct |
48 ms |
145288 KB |
Output is correct |
31 |
Correct |
47 ms |
145236 KB |
Output is correct |
32 |
Correct |
46 ms |
145236 KB |
Output is correct |
33 |
Correct |
46 ms |
145236 KB |
Output is correct |
34 |
Correct |
45 ms |
145232 KB |
Output is correct |
35 |
Correct |
46 ms |
145416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
145236 KB |
Output is correct |
2 |
Correct |
45 ms |
145396 KB |
Output is correct |
3 |
Correct |
45 ms |
145232 KB |
Output is correct |
4 |
Correct |
45 ms |
145232 KB |
Output is correct |
5 |
Correct |
46 ms |
145240 KB |
Output is correct |
6 |
Correct |
47 ms |
145236 KB |
Output is correct |
7 |
Correct |
47 ms |
145188 KB |
Output is correct |
8 |
Correct |
46 ms |
145236 KB |
Output is correct |
9 |
Correct |
46 ms |
145208 KB |
Output is correct |
10 |
Correct |
48 ms |
145640 KB |
Output is correct |
11 |
Correct |
46 ms |
145232 KB |
Output is correct |
12 |
Correct |
45 ms |
145488 KB |
Output is correct |
13 |
Correct |
45 ms |
145388 KB |
Output is correct |
14 |
Correct |
46 ms |
145232 KB |
Output is correct |
15 |
Correct |
45 ms |
145240 KB |
Output is correct |
16 |
Correct |
47 ms |
145228 KB |
Output is correct |
17 |
Correct |
46 ms |
145232 KB |
Output is correct |
18 |
Correct |
99 ms |
145232 KB |
Output is correct |
19 |
Correct |
75 ms |
145424 KB |
Output is correct |
20 |
Correct |
59 ms |
145236 KB |
Output is correct |
21 |
Correct |
75 ms |
145240 KB |
Output is correct |
22 |
Correct |
87 ms |
145556 KB |
Output is correct |
23 |
Correct |
56 ms |
145236 KB |
Output is correct |
24 |
Correct |
53 ms |
145236 KB |
Output is correct |
25 |
Correct |
54 ms |
145420 KB |
Output is correct |
26 |
Correct |
49 ms |
145308 KB |
Output is correct |
27 |
Correct |
57 ms |
145512 KB |
Output is correct |
28 |
Correct |
53 ms |
145188 KB |
Output is correct |
29 |
Correct |
55 ms |
145232 KB |
Output is correct |
30 |
Correct |
59 ms |
145188 KB |
Output is correct |
31 |
Correct |
56 ms |
145424 KB |
Output is correct |
32 |
Correct |
54 ms |
145488 KB |
Output is correct |
33 |
Correct |
56 ms |
145240 KB |
Output is correct |
34 |
Correct |
48 ms |
145424 KB |
Output is correct |
35 |
Correct |
57 ms |
145240 KB |
Output is correct |
36 |
Correct |
48 ms |
145232 KB |
Output is correct |
37 |
Correct |
61 ms |
145316 KB |
Output is correct |
38 |
Correct |
50 ms |
145268 KB |
Output is correct |
39 |
Correct |
65 ms |
145232 KB |
Output is correct |
40 |
Correct |
50 ms |
145232 KB |
Output is correct |
41 |
Correct |
120 ms |
145232 KB |
Output is correct |
42 |
Correct |
85 ms |
145236 KB |
Output is correct |
43 |
Correct |
115 ms |
145392 KB |
Output is correct |
44 |
Correct |
86 ms |
145232 KB |
Output is correct |
45 |
Correct |
119 ms |
145428 KB |
Output is correct |
46 |
Correct |
87 ms |
145336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
145236 KB |
Output is correct |
2 |
Correct |
45 ms |
145396 KB |
Output is correct |
3 |
Correct |
45 ms |
145232 KB |
Output is correct |
4 |
Correct |
45 ms |
145232 KB |
Output is correct |
5 |
Correct |
46 ms |
145240 KB |
Output is correct |
6 |
Correct |
47 ms |
145236 KB |
Output is correct |
7 |
Correct |
47 ms |
145188 KB |
Output is correct |
8 |
Correct |
46 ms |
145236 KB |
Output is correct |
9 |
Correct |
46 ms |
145208 KB |
Output is correct |
10 |
Correct |
48 ms |
145640 KB |
Output is correct |
11 |
Correct |
46 ms |
145232 KB |
Output is correct |
12 |
Correct |
45 ms |
145488 KB |
Output is correct |
13 |
Correct |
45 ms |
145388 KB |
Output is correct |
14 |
Correct |
46 ms |
145232 KB |
Output is correct |
15 |
Correct |
45 ms |
145240 KB |
Output is correct |
16 |
Correct |
47 ms |
145228 KB |
Output is correct |
17 |
Correct |
46 ms |
145232 KB |
Output is correct |
18 |
Correct |
45 ms |
145232 KB |
Output is correct |
19 |
Correct |
46 ms |
145232 KB |
Output is correct |
20 |
Correct |
47 ms |
145232 KB |
Output is correct |
21 |
Correct |
46 ms |
145232 KB |
Output is correct |
22 |
Correct |
47 ms |
145236 KB |
Output is correct |
23 |
Correct |
47 ms |
145372 KB |
Output is correct |
24 |
Correct |
53 ms |
145236 KB |
Output is correct |
25 |
Correct |
48 ms |
145424 KB |
Output is correct |
26 |
Correct |
46 ms |
145232 KB |
Output is correct |
27 |
Correct |
46 ms |
145232 KB |
Output is correct |
28 |
Correct |
47 ms |
145236 KB |
Output is correct |
29 |
Correct |
47 ms |
145188 KB |
Output is correct |
30 |
Correct |
48 ms |
145288 KB |
Output is correct |
31 |
Correct |
47 ms |
145236 KB |
Output is correct |
32 |
Correct |
46 ms |
145236 KB |
Output is correct |
33 |
Correct |
46 ms |
145236 KB |
Output is correct |
34 |
Correct |
45 ms |
145232 KB |
Output is correct |
35 |
Correct |
46 ms |
145416 KB |
Output is correct |
36 |
Correct |
99 ms |
145232 KB |
Output is correct |
37 |
Correct |
75 ms |
145424 KB |
Output is correct |
38 |
Correct |
59 ms |
145236 KB |
Output is correct |
39 |
Correct |
75 ms |
145240 KB |
Output is correct |
40 |
Correct |
87 ms |
145556 KB |
Output is correct |
41 |
Correct |
56 ms |
145236 KB |
Output is correct |
42 |
Correct |
53 ms |
145236 KB |
Output is correct |
43 |
Correct |
54 ms |
145420 KB |
Output is correct |
44 |
Correct |
49 ms |
145308 KB |
Output is correct |
45 |
Correct |
57 ms |
145512 KB |
Output is correct |
46 |
Correct |
53 ms |
145188 KB |
Output is correct |
47 |
Correct |
55 ms |
145232 KB |
Output is correct |
48 |
Correct |
59 ms |
145188 KB |
Output is correct |
49 |
Correct |
56 ms |
145424 KB |
Output is correct |
50 |
Correct |
54 ms |
145488 KB |
Output is correct |
51 |
Correct |
56 ms |
145240 KB |
Output is correct |
52 |
Correct |
48 ms |
145424 KB |
Output is correct |
53 |
Correct |
57 ms |
145240 KB |
Output is correct |
54 |
Correct |
48 ms |
145232 KB |
Output is correct |
55 |
Correct |
61 ms |
145316 KB |
Output is correct |
56 |
Correct |
50 ms |
145268 KB |
Output is correct |
57 |
Correct |
65 ms |
145232 KB |
Output is correct |
58 |
Correct |
50 ms |
145232 KB |
Output is correct |
59 |
Correct |
120 ms |
145232 KB |
Output is correct |
60 |
Correct |
85 ms |
145236 KB |
Output is correct |
61 |
Correct |
115 ms |
145392 KB |
Output is correct |
62 |
Correct |
86 ms |
145232 KB |
Output is correct |
63 |
Correct |
119 ms |
145428 KB |
Output is correct |
64 |
Correct |
87 ms |
145336 KB |
Output is correct |
65 |
Correct |
108 ms |
145236 KB |
Output is correct |
66 |
Correct |
99 ms |
145428 KB |
Output is correct |
67 |
Correct |
99 ms |
145220 KB |
Output is correct |
68 |
Correct |
95 ms |
145424 KB |
Output is correct |
69 |
Correct |
103 ms |
145232 KB |
Output is correct |
70 |
Correct |
123 ms |
145428 KB |
Output is correct |
71 |
Correct |
104 ms |
145244 KB |
Output is correct |
72 |
Correct |
105 ms |
145424 KB |
Output is correct |
73 |
Correct |
99 ms |
145496 KB |
Output is correct |
74 |
Correct |
94 ms |
145236 KB |
Output is correct |
75 |
Correct |
102 ms |
145236 KB |
Output is correct |
76 |
Correct |
112 ms |
145184 KB |
Output is correct |
77 |
Correct |
110 ms |
145236 KB |
Output is correct |
78 |
Correct |
93 ms |
145232 KB |
Output is correct |
79 |
Correct |
95 ms |
145432 KB |
Output is correct |
80 |
Correct |
110 ms |
145428 KB |
Output is correct |
81 |
Correct |
97 ms |
145244 KB |
Output is correct |
82 |
Correct |
110 ms |
145232 KB |
Output is correct |
83 |
Correct |
112 ms |
145428 KB |
Output is correct |
84 |
Correct |
102 ms |
145612 KB |
Output is correct |
85 |
Correct |
106 ms |
145232 KB |
Output is correct |
86 |
Correct |
106 ms |
145424 KB |
Output is correct |
87 |
Correct |
102 ms |
145428 KB |
Output is correct |
88 |
Correct |
120 ms |
145428 KB |
Output is correct |
89 |
Correct |
121 ms |
145316 KB |
Output is correct |
90 |
Correct |
102 ms |
145208 KB |
Output is correct |
91 |
Correct |
117 ms |
145252 KB |
Output is correct |
92 |
Correct |
116 ms |
145244 KB |
Output is correct |
93 |
Correct |
114 ms |
145432 KB |
Output is correct |