#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("trapv")
const int inf = 2e9;
int dp[203][203][203][2];
int n, l, a[203], t[203];
int ans (int x, int y, int z, int c) { //left, right, count, is it at right?
if (x == n + 1 && y == 0) {
if (z == 0) return 0;
return inf;
}
if (z < 0) return inf;
int &ret = dp[x][y][z][c];
if (ret != -1) return ret;
ret = inf;
if (c == 0) {
if (x != n + 1) {
if (y != 0) {
int cost = l - a[x] + a[y];
ret = min(ret, ans(x + 1, y, z, 1) + cost);
if (ans(x + 1, y, z - 1, 1) + cost <= t[x]) {
ret = min(ret, ans(x + 1, y, z - 1, 1) + cost);
}
}
if (x != n + 1) {
int cost = a[x + 1] - a[x];
ret = min(ret, ans(x + 1, y, z, 0) + cost);
if (ans(x + 1, y, z - 1, 0) + cost <= t[x]) {
ret = min(ret, ans(x + 1, y, z - 1, 0) + cost);
}
}
}
} else {
if (y != 0) {
if (x != n + 1) {
int cost = l - a[x] + a[y];
ret = min(ret, ans(x, y - 1, z, 0) + cost);
if (ans(x, y - 1, z - 1, 0) + cost <= t[y]) {
ret = min(ret, ans(x, y - 1, z - 1, 0) + cost);
}
}
if (y != 0) {
int cost = a[y] - a[y - 1];
ret = min(ret, ans(x, y - 1, z, 1) + cost);
if (ans(x, y - 1, z - 1, 1) + cost <= t[y]) {
ret = min(ret, ans(x, y - 1, z - 1, 1) + cost);
}
}
}
}
return ret;
}
void solve () {
cin >> n >> l;
a[0] = 0; a[n + 1] = l;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
memset(dp, -1, sizeof(dp));
int ret = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= n + 1; j++) {
for (int k = j + 1; k <= n + 1; k++) {
if (ans(k, j, i, 0) != inf || ans(k, j, i, 1) != inf) {
ret = i;
}
}
}
}
cout << ret << '\n';
}
signed main () {
ios::sync_with_stdio(0); cin.tie(0);
int tc = 1; //cin >> tc;
while (tc--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
65884 KB |
Output is correct |
2 |
Correct |
7 ms |
65732 KB |
Output is correct |
3 |
Correct |
8 ms |
65884 KB |
Output is correct |
4 |
Correct |
9 ms |
65884 KB |
Output is correct |
5 |
Correct |
9 ms |
65884 KB |
Output is correct |
6 |
Correct |
9 ms |
65732 KB |
Output is correct |
7 |
Correct |
8 ms |
65884 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 |
65736 KB |
Output is correct |
11 |
Correct |
8 ms |
65884 KB |
Output is correct |
12 |
Correct |
8 ms |
65884 KB |
Output is correct |
13 |
Correct |
9 ms |
65884 KB |
Output is correct |
14 |
Correct |
8 ms |
65688 KB |
Output is correct |
15 |
Correct |
8 ms |
65884 KB |
Output is correct |
16 |
Correct |
8 ms |
65780 KB |
Output is correct |
17 |
Correct |
8 ms |
65880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
65884 KB |
Output is correct |
2 |
Correct |
7 ms |
65732 KB |
Output is correct |
3 |
Correct |
8 ms |
65884 KB |
Output is correct |
4 |
Correct |
9 ms |
65884 KB |
Output is correct |
5 |
Correct |
9 ms |
65884 KB |
Output is correct |
6 |
Correct |
9 ms |
65732 KB |
Output is correct |
7 |
Correct |
8 ms |
65884 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 |
65736 KB |
Output is correct |
11 |
Correct |
8 ms |
65884 KB |
Output is correct |
12 |
Correct |
8 ms |
65884 KB |
Output is correct |
13 |
Correct |
9 ms |
65884 KB |
Output is correct |
14 |
Correct |
8 ms |
65688 KB |
Output is correct |
15 |
Correct |
8 ms |
65884 KB |
Output is correct |
16 |
Correct |
8 ms |
65780 KB |
Output is correct |
17 |
Correct |
8 ms |
65880 KB |
Output is correct |
18 |
Runtime error |
49 ms |
133268 KB |
Execution killed with signal 6 |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
65884 KB |
Output is correct |
2 |
Correct |
7 ms |
65732 KB |
Output is correct |
3 |
Correct |
8 ms |
65884 KB |
Output is correct |
4 |
Correct |
9 ms |
65884 KB |
Output is correct |
5 |
Correct |
9 ms |
65884 KB |
Output is correct |
6 |
Correct |
9 ms |
65732 KB |
Output is correct |
7 |
Correct |
8 ms |
65884 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 |
65736 KB |
Output is correct |
11 |
Correct |
8 ms |
65884 KB |
Output is correct |
12 |
Correct |
8 ms |
65884 KB |
Output is correct |
13 |
Correct |
9 ms |
65884 KB |
Output is correct |
14 |
Correct |
8 ms |
65688 KB |
Output is correct |
15 |
Correct |
8 ms |
65884 KB |
Output is correct |
16 |
Correct |
8 ms |
65780 KB |
Output is correct |
17 |
Correct |
8 ms |
65880 KB |
Output is correct |
18 |
Correct |
238 ms |
65884 KB |
Output is correct |
19 |
Correct |
120 ms |
65884 KB |
Output is correct |
20 |
Correct |
50 ms |
65880 KB |
Output is correct |
21 |
Correct |
106 ms |
65924 KB |
Output is correct |
22 |
Correct |
161 ms |
65884 KB |
Output is correct |
23 |
Correct |
43 ms |
65884 KB |
Output is correct |
24 |
Correct |
30 ms |
65696 KB |
Output is correct |
25 |
Correct |
41 ms |
65884 KB |
Output is correct |
26 |
Correct |
15 ms |
65880 KB |
Output is correct |
27 |
Correct |
43 ms |
65944 KB |
Output is correct |
28 |
Correct |
28 ms |
65880 KB |
Output is correct |
29 |
Correct |
41 ms |
65884 KB |
Output is correct |
30 |
Correct |
32 ms |
65880 KB |
Output is correct |
31 |
Correct |
40 ms |
65884 KB |
Output is correct |
32 |
Correct |
21 ms |
65884 KB |
Output is correct |
33 |
Correct |
41 ms |
65884 KB |
Output is correct |
34 |
Correct |
19 ms |
65884 KB |
Output is correct |
35 |
Correct |
40 ms |
65884 KB |
Output is correct |
36 |
Correct |
19 ms |
65740 KB |
Output is correct |
37 |
Correct |
44 ms |
65884 KB |
Output is correct |
38 |
Correct |
21 ms |
65884 KB |
Output is correct |
39 |
Correct |
46 ms |
65884 KB |
Output is correct |
40 |
Correct |
29 ms |
65880 KB |
Output is correct |
41 |
Correct |
317 ms |
65884 KB |
Output is correct |
42 |
Correct |
179 ms |
65884 KB |
Output is correct |
43 |
Correct |
335 ms |
65936 KB |
Output is correct |
44 |
Correct |
177 ms |
65936 KB |
Output is correct |
45 |
Correct |
352 ms |
65880 KB |
Output is correct |
46 |
Correct |
177 ms |
65884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
65884 KB |
Output is correct |
2 |
Correct |
7 ms |
65732 KB |
Output is correct |
3 |
Correct |
8 ms |
65884 KB |
Output is correct |
4 |
Correct |
9 ms |
65884 KB |
Output is correct |
5 |
Correct |
9 ms |
65884 KB |
Output is correct |
6 |
Correct |
9 ms |
65732 KB |
Output is correct |
7 |
Correct |
8 ms |
65884 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 |
65736 KB |
Output is correct |
11 |
Correct |
8 ms |
65884 KB |
Output is correct |
12 |
Correct |
8 ms |
65884 KB |
Output is correct |
13 |
Correct |
9 ms |
65884 KB |
Output is correct |
14 |
Correct |
8 ms |
65688 KB |
Output is correct |
15 |
Correct |
8 ms |
65884 KB |
Output is correct |
16 |
Correct |
8 ms |
65780 KB |
Output is correct |
17 |
Correct |
8 ms |
65880 KB |
Output is correct |
18 |
Runtime error |
49 ms |
133268 KB |
Execution killed with signal 6 |
19 |
Halted |
0 ms |
0 KB |
- |