#include <bits/stdc++.h>
using namespace std;
int mPrev[2][405][205];
int atual[2][405][205];
int INF = 0x3f3f3f3f;
int32_t main() {
//freopen("in", "r", stdin);
int n, l;
cin >> n >> l;
vector<int> x1(n), t1(n);
for (int i = 0; i < n; i++) {
cin >> x1[i];
}
for (int i = 0; i < n; i++) {
cin >> t1[i];
}
vector<int> v, ti;
for (int i = 0; i < n; i++) {
v.push_back(x1[i] - l);
ti.push_back(t1[i]);
}
v.push_back(0);
ti.push_back(-1);
for (int i = 0; i < n; i++) {
v.push_back(x1[i]);
ti.push_back(t1[i]);
}
// inicializar dp
for (int i = 0; i < 405; i++) {
for (int j = 0; j < 205; j++) {
mPrev[0][i][j] = mPrev[1][i][j] = INF;
}
}
mPrev[0][n][0] = mPrev[1][n][0] = 0;
int tam = 2*n + 1;
// calcular dp porra lesgo
int ans = 0;
for (int t = 1; t <= n; t++) {
for (int i = 0; i < 405; i++) {
for (int j = 0; j < 205; j++) {
atual[0][i][j] = atual[1][i][j] = INF;
}
}
for (int qtd = 0; qtd <= (t + 1); qtd++) {
for (int i = 0; i < (tam - t); i++) {
int j = (i + t);
int d1 = (v[i + 1] - v[i]);
int d2 = (v[j] - v[i]);
int d3 = (v[j] - v[j - 1]);
// calcular para estamos no i
atual[0][i][qtd] = min(atual[0][i][qtd], mPrev[0][i + 1][qtd] + d1);
atual[0][i][qtd] = min(atual[0][i][qtd], mPrev[1][i + 1][qtd] + d2);
// consegue aumentar
if (qtd > 0) {
if ((mPrev[0][i + 1][qtd - 1] + d1) <= ti[i]) atual[0][i][qtd] = min(atual[0][i][qtd], mPrev[0][i + 1][qtd - 1] + d1);
if ((mPrev[1][i + 1][qtd - 1] + d2) <= ti[i]) atual[0][i][qtd] = min(atual[0][i][qtd], mPrev[1][i + 1][qtd - 1] + d2);
}
// calcular para estamos no j
atual[1][i][qtd] = min(atual[1][i][qtd], mPrev[0][i][qtd] + d2);
atual[1][i][qtd] = min(atual[1][i][qtd], mPrev[1][i][qtd] + d3);
// consegue aumentar
if (qtd > 0) {
if ((mPrev[0][i][qtd - 1] + d2) <= ti[j]) atual[1][i][qtd] = min(atual[1][i][qtd], mPrev[0][i][qtd - 1] + d2);
if ((mPrev[1][i][qtd - 1] + d3) <= ti[j]) atual[1][i][qtd] = min(atual[1][i][qtd], mPrev[1][i][qtd - 1] + d3);
}
// atualizar resposta
if ((atual[0][i][qtd] < INF) || (atual[1][i][qtd] < INF)) ans = max(ans, qtd);
}
}
swap(atual, mPrev);
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1628 KB |
Output is correct |
2 |
Correct |
2 ms |
1628 KB |
Output is correct |
3 |
Correct |
2 ms |
1628 KB |
Output is correct |
4 |
Correct |
2 ms |
1628 KB |
Output is correct |
5 |
Correct |
2 ms |
1628 KB |
Output is correct |
6 |
Correct |
3 ms |
1612 KB |
Output is correct |
7 |
Correct |
3 ms |
1628 KB |
Output is correct |
8 |
Correct |
3 ms |
1628 KB |
Output is correct |
9 |
Correct |
3 ms |
1624 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
3 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1628 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
2 ms |
1744 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
3 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1628 KB |
Output is correct |
2 |
Correct |
2 ms |
1628 KB |
Output is correct |
3 |
Correct |
2 ms |
1628 KB |
Output is correct |
4 |
Correct |
2 ms |
1628 KB |
Output is correct |
5 |
Correct |
2 ms |
1628 KB |
Output is correct |
6 |
Correct |
3 ms |
1612 KB |
Output is correct |
7 |
Correct |
3 ms |
1628 KB |
Output is correct |
8 |
Correct |
3 ms |
1628 KB |
Output is correct |
9 |
Correct |
3 ms |
1624 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
3 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1628 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
2 ms |
1744 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
3 ms |
1628 KB |
Output is correct |
18 |
Correct |
4 ms |
1628 KB |
Output is correct |
19 |
Correct |
2 ms |
1628 KB |
Output is correct |
20 |
Correct |
3 ms |
1624 KB |
Output is correct |
21 |
Correct |
3 ms |
1628 KB |
Output is correct |
22 |
Correct |
3 ms |
1736 KB |
Output is correct |
23 |
Correct |
4 ms |
1628 KB |
Output is correct |
24 |
Correct |
3 ms |
1628 KB |
Output is correct |
25 |
Correct |
3 ms |
1628 KB |
Output is correct |
26 |
Correct |
4 ms |
1628 KB |
Output is correct |
27 |
Correct |
2 ms |
1628 KB |
Output is correct |
28 |
Correct |
2 ms |
1628 KB |
Output is correct |
29 |
Correct |
3 ms |
1628 KB |
Output is correct |
30 |
Correct |
3 ms |
1628 KB |
Output is correct |
31 |
Correct |
4 ms |
1624 KB |
Output is correct |
32 |
Correct |
3 ms |
1624 KB |
Output is correct |
33 |
Correct |
3 ms |
1628 KB |
Output is correct |
34 |
Correct |
4 ms |
1676 KB |
Output is correct |
35 |
Correct |
4 ms |
1740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1628 KB |
Output is correct |
2 |
Correct |
2 ms |
1628 KB |
Output is correct |
3 |
Correct |
2 ms |
1628 KB |
Output is correct |
4 |
Correct |
2 ms |
1628 KB |
Output is correct |
5 |
Correct |
2 ms |
1628 KB |
Output is correct |
6 |
Correct |
3 ms |
1612 KB |
Output is correct |
7 |
Correct |
3 ms |
1628 KB |
Output is correct |
8 |
Correct |
3 ms |
1628 KB |
Output is correct |
9 |
Correct |
3 ms |
1624 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
3 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1628 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
2 ms |
1744 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
3 ms |
1628 KB |
Output is correct |
18 |
Correct |
51 ms |
1748 KB |
Output is correct |
19 |
Correct |
34 ms |
1628 KB |
Output is correct |
20 |
Correct |
24 ms |
1628 KB |
Output is correct |
21 |
Correct |
32 ms |
1748 KB |
Output is correct |
22 |
Correct |
41 ms |
1628 KB |
Output is correct |
23 |
Correct |
20 ms |
1624 KB |
Output is correct |
24 |
Correct |
17 ms |
1748 KB |
Output is correct |
25 |
Correct |
19 ms |
1880 KB |
Output is correct |
26 |
Correct |
11 ms |
1744 KB |
Output is correct |
27 |
Correct |
20 ms |
1628 KB |
Output is correct |
28 |
Correct |
16 ms |
1624 KB |
Output is correct |
29 |
Correct |
20 ms |
1624 KB |
Output is correct |
30 |
Correct |
17 ms |
1628 KB |
Output is correct |
31 |
Correct |
19 ms |
1628 KB |
Output is correct |
32 |
Correct |
13 ms |
1744 KB |
Output is correct |
33 |
Correct |
19 ms |
1628 KB |
Output is correct |
34 |
Correct |
10 ms |
1628 KB |
Output is correct |
35 |
Correct |
19 ms |
1744 KB |
Output is correct |
36 |
Correct |
12 ms |
1624 KB |
Output is correct |
37 |
Correct |
20 ms |
1628 KB |
Output is correct |
38 |
Correct |
14 ms |
1744 KB |
Output is correct |
39 |
Correct |
22 ms |
1880 KB |
Output is correct |
40 |
Correct |
15 ms |
1628 KB |
Output is correct |
41 |
Correct |
62 ms |
1720 KB |
Output is correct |
42 |
Correct |
43 ms |
1628 KB |
Output is correct |
43 |
Correct |
62 ms |
1624 KB |
Output is correct |
44 |
Correct |
47 ms |
1624 KB |
Output is correct |
45 |
Correct |
62 ms |
1624 KB |
Output is correct |
46 |
Correct |
45 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1628 KB |
Output is correct |
2 |
Correct |
2 ms |
1628 KB |
Output is correct |
3 |
Correct |
2 ms |
1628 KB |
Output is correct |
4 |
Correct |
2 ms |
1628 KB |
Output is correct |
5 |
Correct |
2 ms |
1628 KB |
Output is correct |
6 |
Correct |
3 ms |
1612 KB |
Output is correct |
7 |
Correct |
3 ms |
1628 KB |
Output is correct |
8 |
Correct |
3 ms |
1628 KB |
Output is correct |
9 |
Correct |
3 ms |
1624 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
3 ms |
1628 KB |
Output is correct |
13 |
Correct |
3 ms |
1628 KB |
Output is correct |
14 |
Correct |
2 ms |
1628 KB |
Output is correct |
15 |
Correct |
2 ms |
1744 KB |
Output is correct |
16 |
Correct |
3 ms |
1628 KB |
Output is correct |
17 |
Correct |
3 ms |
1628 KB |
Output is correct |
18 |
Correct |
4 ms |
1628 KB |
Output is correct |
19 |
Correct |
2 ms |
1628 KB |
Output is correct |
20 |
Correct |
3 ms |
1624 KB |
Output is correct |
21 |
Correct |
3 ms |
1628 KB |
Output is correct |
22 |
Correct |
3 ms |
1736 KB |
Output is correct |
23 |
Correct |
4 ms |
1628 KB |
Output is correct |
24 |
Correct |
3 ms |
1628 KB |
Output is correct |
25 |
Correct |
3 ms |
1628 KB |
Output is correct |
26 |
Correct |
4 ms |
1628 KB |
Output is correct |
27 |
Correct |
2 ms |
1628 KB |
Output is correct |
28 |
Correct |
2 ms |
1628 KB |
Output is correct |
29 |
Correct |
3 ms |
1628 KB |
Output is correct |
30 |
Correct |
3 ms |
1628 KB |
Output is correct |
31 |
Correct |
4 ms |
1624 KB |
Output is correct |
32 |
Correct |
3 ms |
1624 KB |
Output is correct |
33 |
Correct |
3 ms |
1628 KB |
Output is correct |
34 |
Correct |
4 ms |
1676 KB |
Output is correct |
35 |
Correct |
4 ms |
1740 KB |
Output is correct |
36 |
Correct |
51 ms |
1748 KB |
Output is correct |
37 |
Correct |
34 ms |
1628 KB |
Output is correct |
38 |
Correct |
24 ms |
1628 KB |
Output is correct |
39 |
Correct |
32 ms |
1748 KB |
Output is correct |
40 |
Correct |
41 ms |
1628 KB |
Output is correct |
41 |
Correct |
20 ms |
1624 KB |
Output is correct |
42 |
Correct |
17 ms |
1748 KB |
Output is correct |
43 |
Correct |
19 ms |
1880 KB |
Output is correct |
44 |
Correct |
11 ms |
1744 KB |
Output is correct |
45 |
Correct |
20 ms |
1628 KB |
Output is correct |
46 |
Correct |
16 ms |
1624 KB |
Output is correct |
47 |
Correct |
20 ms |
1624 KB |
Output is correct |
48 |
Correct |
17 ms |
1628 KB |
Output is correct |
49 |
Correct |
19 ms |
1628 KB |
Output is correct |
50 |
Correct |
13 ms |
1744 KB |
Output is correct |
51 |
Correct |
19 ms |
1628 KB |
Output is correct |
52 |
Correct |
10 ms |
1628 KB |
Output is correct |
53 |
Correct |
19 ms |
1744 KB |
Output is correct |
54 |
Correct |
12 ms |
1624 KB |
Output is correct |
55 |
Correct |
20 ms |
1628 KB |
Output is correct |
56 |
Correct |
14 ms |
1744 KB |
Output is correct |
57 |
Correct |
22 ms |
1880 KB |
Output is correct |
58 |
Correct |
15 ms |
1628 KB |
Output is correct |
59 |
Correct |
62 ms |
1720 KB |
Output is correct |
60 |
Correct |
43 ms |
1628 KB |
Output is correct |
61 |
Correct |
62 ms |
1624 KB |
Output is correct |
62 |
Correct |
47 ms |
1624 KB |
Output is correct |
63 |
Correct |
62 ms |
1624 KB |
Output is correct |
64 |
Correct |
45 ms |
1628 KB |
Output is correct |
65 |
Correct |
64 ms |
1628 KB |
Output is correct |
66 |
Correct |
53 ms |
1628 KB |
Output is correct |
67 |
Correct |
54 ms |
1628 KB |
Output is correct |
68 |
Correct |
47 ms |
1628 KB |
Output is correct |
69 |
Correct |
56 ms |
1628 KB |
Output is correct |
70 |
Correct |
57 ms |
1624 KB |
Output is correct |
71 |
Correct |
56 ms |
1628 KB |
Output is correct |
72 |
Correct |
64 ms |
1724 KB |
Output is correct |
73 |
Correct |
51 ms |
1628 KB |
Output is correct |
74 |
Correct |
51 ms |
1628 KB |
Output is correct |
75 |
Correct |
53 ms |
1624 KB |
Output is correct |
76 |
Correct |
64 ms |
1624 KB |
Output is correct |
77 |
Correct |
60 ms |
1728 KB |
Output is correct |
78 |
Correct |
51 ms |
1628 KB |
Output is correct |
79 |
Correct |
49 ms |
1628 KB |
Output is correct |
80 |
Correct |
60 ms |
1720 KB |
Output is correct |
81 |
Correct |
50 ms |
1628 KB |
Output is correct |
82 |
Correct |
54 ms |
1624 KB |
Output is correct |
83 |
Correct |
62 ms |
1728 KB |
Output is correct |
84 |
Correct |
54 ms |
1628 KB |
Output is correct |
85 |
Correct |
58 ms |
1624 KB |
Output is correct |
86 |
Correct |
57 ms |
1628 KB |
Output is correct |
87 |
Correct |
53 ms |
1624 KB |
Output is correct |
88 |
Correct |
68 ms |
1628 KB |
Output is correct |
89 |
Correct |
63 ms |
1628 KB |
Output is correct |
90 |
Correct |
53 ms |
1628 KB |
Output is correct |
91 |
Correct |
64 ms |
1628 KB |
Output is correct |
92 |
Correct |
63 ms |
1624 KB |
Output is correct |
93 |
Correct |
66 ms |
1720 KB |
Output is correct |