#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;
priority_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.top();
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 |
1 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 |
1 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 |
460 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 |
1 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 |
1 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 |
460 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 |
2 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 |
1092 KB |
Output is correct |
27 |
Correct |
1 ms |
580 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
2 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 |
1084 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 |
1 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 |
1 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 |
460 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 |
934 ms |
111220 KB |
Output is correct |
19 |
Correct |
442 ms |
66772 KB |
Output is correct |
20 |
Correct |
139 ms |
35584 KB |
Output is correct |
21 |
Correct |
355 ms |
63272 KB |
Output is correct |
22 |
Correct |
621 ms |
84200 KB |
Output is correct |
23 |
Correct |
165 ms |
30676 KB |
Output is correct |
24 |
Correct |
42 ms |
23448 KB |
Output is correct |
25 |
Correct |
124 ms |
29904 KB |
Output is correct |
26 |
Correct |
15 ms |
11084 KB |
Output is correct |
27 |
Correct |
155 ms |
31208 KB |
Output is correct |
28 |
Correct |
38 ms |
21612 KB |
Output is correct |
29 |
Correct |
128 ms |
30972 KB |
Output is correct |
30 |
Correct |
38 ms |
24648 KB |
Output is correct |
31 |
Correct |
117 ms |
29152 KB |
Output is correct |
32 |
Correct |
36 ms |
15812 KB |
Output is correct |
33 |
Correct |
126 ms |
29128 KB |
Output is correct |
34 |
Correct |
17 ms |
10444 KB |
Output is correct |
35 |
Correct |
35 ms |
28176 KB |
Output is correct |
36 |
Correct |
17 ms |
13708 KB |
Output is correct |
37 |
Correct |
46 ms |
30052 KB |
Output is correct |
38 |
Correct |
40 ms |
17032 KB |
Output is correct |
39 |
Correct |
46 ms |
31244 KB |
Output is correct |
40 |
Correct |
23 ms |
18572 KB |
Output is correct |
41 |
Correct |
1570 ms |
141868 KB |
Output is correct |
42 |
Correct |
56 ms |
87480 KB |
Output is correct |
43 |
Correct |
1471 ms |
141820 KB |
Output is correct |
44 |
Correct |
50 ms |
86476 KB |
Output is correct |
45 |
Correct |
1587 ms |
142012 KB |
Output is correct |
46 |
Correct |
56 ms |
87464 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 |
1 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 |
1 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 |
460 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 |
2 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 |
1092 KB |
Output is correct |
27 |
Correct |
1 ms |
580 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
2 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 |
1084 KB |
Output is correct |
35 |
Correct |
1 ms |
1100 KB |
Output is correct |
36 |
Correct |
934 ms |
111220 KB |
Output is correct |
37 |
Correct |
442 ms |
66772 KB |
Output is correct |
38 |
Correct |
139 ms |
35584 KB |
Output is correct |
39 |
Correct |
355 ms |
63272 KB |
Output is correct |
40 |
Correct |
621 ms |
84200 KB |
Output is correct |
41 |
Correct |
165 ms |
30676 KB |
Output is correct |
42 |
Correct |
42 ms |
23448 KB |
Output is correct |
43 |
Correct |
124 ms |
29904 KB |
Output is correct |
44 |
Correct |
15 ms |
11084 KB |
Output is correct |
45 |
Correct |
155 ms |
31208 KB |
Output is correct |
46 |
Correct |
38 ms |
21612 KB |
Output is correct |
47 |
Correct |
128 ms |
30972 KB |
Output is correct |
48 |
Correct |
38 ms |
24648 KB |
Output is correct |
49 |
Correct |
117 ms |
29152 KB |
Output is correct |
50 |
Correct |
36 ms |
15812 KB |
Output is correct |
51 |
Correct |
126 ms |
29128 KB |
Output is correct |
52 |
Correct |
17 ms |
10444 KB |
Output is correct |
53 |
Correct |
35 ms |
28176 KB |
Output is correct |
54 |
Correct |
17 ms |
13708 KB |
Output is correct |
55 |
Correct |
46 ms |
30052 KB |
Output is correct |
56 |
Correct |
40 ms |
17032 KB |
Output is correct |
57 |
Correct |
46 ms |
31244 KB |
Output is correct |
58 |
Correct |
23 ms |
18572 KB |
Output is correct |
59 |
Correct |
1570 ms |
141868 KB |
Output is correct |
60 |
Correct |
56 ms |
87480 KB |
Output is correct |
61 |
Correct |
1471 ms |
141820 KB |
Output is correct |
62 |
Correct |
50 ms |
86476 KB |
Output is correct |
63 |
Correct |
1587 ms |
142012 KB |
Output is correct |
64 |
Correct |
56 ms |
87464 KB |
Output is correct |
65 |
Correct |
1091 ms |
129328 KB |
Output is correct |
66 |
Correct |
1000 ms |
119740 KB |
Output is correct |
67 |
Correct |
781 ms |
115080 KB |
Output is correct |
68 |
Correct |
719 ms |
101084 KB |
Output is correct |
69 |
Correct |
1164 ms |
128128 KB |
Output is correct |
70 |
Correct |
1045 ms |
117108 KB |
Output is correct |
71 |
Correct |
793 ms |
124460 KB |
Output is correct |
72 |
Correct |
1196 ms |
125868 KB |
Output is correct |
73 |
Correct |
393 ms |
111212 KB |
Output is correct |
74 |
Correct |
769 ms |
104404 KB |
Output is correct |
75 |
Correct |
701 ms |
120952 KB |
Output is correct |
76 |
Correct |
1410 ms |
130576 KB |
Output is correct |
77 |
Correct |
1060 ms |
136744 KB |
Output is correct |
78 |
Correct |
867 ms |
99012 KB |
Output is correct |
79 |
Correct |
898 ms |
111644 KB |
Output is correct |
80 |
Correct |
1253 ms |
128140 KB |
Output is correct |
81 |
Correct |
661 ms |
112852 KB |
Output is correct |
82 |
Correct |
489 ms |
112328 KB |
Output is correct |
83 |
Correct |
1210 ms |
141860 KB |
Output is correct |
84 |
Correct |
548 ms |
117120 KB |
Output is correct |
85 |
Correct |
555 ms |
126884 KB |
Output is correct |
86 |
Correct |
568 ms |
124388 KB |
Output is correct |
87 |
Correct |
991 ms |
120868 KB |
Output is correct |
88 |
Correct |
1932 ms |
143144 KB |
Output is correct |
89 |
Correct |
1425 ms |
143140 KB |
Output is correct |
90 |
Correct |
73 ms |
109956 KB |
Output is correct |
91 |
Execution timed out |
2060 ms |
143196 KB |
Time limit exceeded |
92 |
Halted |
0 ms |
0 KB |
- |