#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
const int INF = 2e9 + 5;
int n, l, ans;
long long X[MAXN], t[MAXN];
long long dp[MAXN][MAXN][MAXN][2];
long long f(long long x)
{
return min(x, l - x);
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> l;
for(int i = 1; i <= n; i++)
{
cin >> X[i];
}
for(int i = 1; i <= n; i++)
{
cin >> t[i];
}
for(int i = 0; i <= n; i++)
{
for(int j = 0; j <= n; j++)
{
for(int k = 0; k <= n; k++)
{
for(int h = 0; h < 2; h++)
{
dp[i][j][k][h] = INF;
}
}
}
}
dp[0][0][0][0] = 0;
queue <tuple <long long, int, int, int, int> > pq;
pq.push(make_tuple(0, 0, 0, 0, 0));
while(pq.empty() == false)
{
int d, l, r, k, h;
tie(d, l, r, k, h) = pq.front();
pq.pop();
d = -d;
ans = max(ans, k);
if(d == dp[l][r][k][h])
{
int prv = l - 1;
if(prv == -1)
{
prv = n;
}
if(prv != r)
{
long long dist = d + f(abs(X[prv] - (h ? X[r] : X[l])));
if(dist <= t[prv] and prv != 0)
{
if(dp[prv][r][k + 1][0] > dist)
{
dp[prv][r][k + 1][0] = dist;
pq.push(make_tuple(-dist, prv, r, k + 1, 0));
}
}
else
{
if(dp[prv][r][k][0] > dist)
{
dp[prv][r][k][0] = dist;
pq.push(make_tuple(-dist, prv, r, k, 0));
}
}
}
int nxt = r + 1;
if(nxt != l)
{
long long dist = d + f(abs(X[nxt] - (h ? X[r] : X[l])));
if(dist <= t[nxt] and nxt != 0)
{
if(dp[l][nxt][k + 1][1] > dist)
{
dp[l][nxt][k + 1][1] = dist;
pq.push(make_tuple(-dist, l, nxt, k + 1, 1));
}
}
else
{
if(dp[l][nxt][k][1] > dist)
{
dp[l][nxt][k][1] = dist;
pq.push(make_tuple(-dist, l, nxt, k, 1));
}
}
}
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
0 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
488 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
0 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
488 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
844 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
972 KB |
Output is correct |
26 |
Correct |
1 ms |
972 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
1 ms |
1100 KB |
Output is correct |
31 |
Correct |
1 ms |
972 KB |
Output is correct |
32 |
Correct |
1 ms |
972 KB |
Output is correct |
33 |
Correct |
1 ms |
1100 KB |
Output is correct |
34 |
Correct |
1 ms |
1100 KB |
Output is correct |
35 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
0 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
488 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
18 |
Correct |
145 ms |
105716 KB |
Output is correct |
19 |
Correct |
78 ms |
64268 KB |
Output is correct |
20 |
Correct |
33 ms |
34216 KB |
Output is correct |
21 |
Correct |
67 ms |
60580 KB |
Output is correct |
22 |
Correct |
101 ms |
78736 KB |
Output is correct |
23 |
Correct |
33 ms |
29380 KB |
Output is correct |
24 |
Correct |
19 ms |
22752 KB |
Output is correct |
25 |
Correct |
28 ms |
28724 KB |
Output is correct |
26 |
Correct |
8 ms |
10956 KB |
Output is correct |
27 |
Correct |
31 ms |
29952 KB |
Output is correct |
28 |
Correct |
14 ms |
21156 KB |
Output is correct |
29 |
Correct |
31 ms |
30540 KB |
Output is correct |
30 |
Correct |
19 ms |
23896 KB |
Output is correct |
31 |
Correct |
30 ms |
28624 KB |
Output is correct |
32 |
Correct |
12 ms |
14924 KB |
Output is correct |
33 |
Correct |
28 ms |
28604 KB |
Output is correct |
34 |
Correct |
9 ms |
10264 KB |
Output is correct |
35 |
Correct |
21 ms |
27724 KB |
Output is correct |
36 |
Correct |
12 ms |
13260 KB |
Output is correct |
37 |
Correct |
25 ms |
29616 KB |
Output is correct |
38 |
Correct |
11 ms |
16332 KB |
Output is correct |
39 |
Correct |
19 ms |
30788 KB |
Output is correct |
40 |
Correct |
13 ms |
18124 KB |
Output is correct |
41 |
Correct |
200 ms |
130912 KB |
Output is correct |
42 |
Correct |
52 ms |
87136 KB |
Output is correct |
43 |
Correct |
199 ms |
130884 KB |
Output is correct |
44 |
Correct |
46 ms |
86144 KB |
Output is correct |
45 |
Correct |
199 ms |
130820 KB |
Output is correct |
46 |
Correct |
44 ms |
87108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
0 ms |
588 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
488 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
844 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
972 KB |
Output is correct |
26 |
Correct |
1 ms |
972 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
1 ms |
1100 KB |
Output is correct |
31 |
Correct |
1 ms |
972 KB |
Output is correct |
32 |
Correct |
1 ms |
972 KB |
Output is correct |
33 |
Correct |
1 ms |
1100 KB |
Output is correct |
34 |
Correct |
1 ms |
1100 KB |
Output is correct |
35 |
Correct |
1 ms |
1100 KB |
Output is correct |
36 |
Correct |
145 ms |
105716 KB |
Output is correct |
37 |
Correct |
78 ms |
64268 KB |
Output is correct |
38 |
Correct |
33 ms |
34216 KB |
Output is correct |
39 |
Correct |
67 ms |
60580 KB |
Output is correct |
40 |
Correct |
101 ms |
78736 KB |
Output is correct |
41 |
Correct |
33 ms |
29380 KB |
Output is correct |
42 |
Correct |
19 ms |
22752 KB |
Output is correct |
43 |
Correct |
28 ms |
28724 KB |
Output is correct |
44 |
Correct |
8 ms |
10956 KB |
Output is correct |
45 |
Correct |
31 ms |
29952 KB |
Output is correct |
46 |
Correct |
14 ms |
21156 KB |
Output is correct |
47 |
Correct |
31 ms |
30540 KB |
Output is correct |
48 |
Correct |
19 ms |
23896 KB |
Output is correct |
49 |
Correct |
30 ms |
28624 KB |
Output is correct |
50 |
Correct |
12 ms |
14924 KB |
Output is correct |
51 |
Correct |
28 ms |
28604 KB |
Output is correct |
52 |
Correct |
9 ms |
10264 KB |
Output is correct |
53 |
Correct |
21 ms |
27724 KB |
Output is correct |
54 |
Correct |
12 ms |
13260 KB |
Output is correct |
55 |
Correct |
25 ms |
29616 KB |
Output is correct |
56 |
Correct |
11 ms |
16332 KB |
Output is correct |
57 |
Correct |
19 ms |
30788 KB |
Output is correct |
58 |
Correct |
13 ms |
18124 KB |
Output is correct |
59 |
Correct |
200 ms |
130912 KB |
Output is correct |
60 |
Correct |
52 ms |
87136 KB |
Output is correct |
61 |
Correct |
199 ms |
130884 KB |
Output is correct |
62 |
Correct |
46 ms |
86144 KB |
Output is correct |
63 |
Correct |
199 ms |
130820 KB |
Output is correct |
64 |
Correct |
44 ms |
87108 KB |
Output is correct |
65 |
Correct |
158 ms |
117908 KB |
Output is correct |
66 |
Correct |
139 ms |
108228 KB |
Output is correct |
67 |
Correct |
124 ms |
103460 KB |
Output is correct |
68 |
Correct |
119 ms |
95540 KB |
Output is correct |
69 |
Correct |
188 ms |
116868 KB |
Output is correct |
70 |
Correct |
177 ms |
112400 KB |
Output is correct |
71 |
Correct |
141 ms |
112836 KB |
Output is correct |
72 |
Correct |
178 ms |
115100 KB |
Output is correct |
73 |
Correct |
90 ms |
105336 KB |
Output is correct |
74 |
Correct |
139 ms |
99436 KB |
Output is correct |
75 |
Correct |
124 ms |
109324 KB |
Output is correct |
76 |
Correct |
239 ms |
126096 KB |
Output is correct |
77 |
Correct |
178 ms |
125348 KB |
Output is correct |
78 |
Correct |
149 ms |
97220 KB |
Output is correct |
79 |
Correct |
141 ms |
100156 KB |
Output is correct |
80 |
Correct |
225 ms |
123668 KB |
Output is correct |
81 |
Correct |
120 ms |
101232 KB |
Output is correct |
82 |
Correct |
109 ms |
106512 KB |
Output is correct |
83 |
Correct |
180 ms |
130532 KB |
Output is correct |
84 |
Correct |
120 ms |
111300 KB |
Output is correct |
85 |
Correct |
110 ms |
121092 KB |
Output is correct |
86 |
Correct |
119 ms |
118668 KB |
Output is correct |
87 |
Correct |
148 ms |
109508 KB |
Output is correct |
88 |
Correct |
262 ms |
132516 KB |
Output is correct |
89 |
Correct |
216 ms |
132056 KB |
Output is correct |
90 |
Correct |
56 ms |
109604 KB |
Output is correct |
91 |
Correct |
247 ms |
132568 KB |
Output is correct |
92 |
Correct |
188 ms |
132088 KB |
Output is correct |
93 |
Correct |
65 ms |
128068 KB |
Output is correct |