#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define t4 tuple <int, int, int, int>
int n, l, X[205], T[205], dist[205][205][205][2];
void solve(){
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++)dist[i][j][k][0] = dist[i][j][k][1] = 1e18;
priority_queue <pair <int, t4> , vector <pair <int, t4> >, greater <pair <int, t4> > > pq;
pq.push({X[1], {2, n, (T[1] >= X[1]), 0}});
dist[2][n][T[1] >= X[1]][0] = X[1];
pq.push({l - X[n], {1, n - 1, (T[n] >= l - X[n]), 1}});
dist[1][n - 1][T[n] >= l - X[n]][1] = l - X[n];
while(!pq.empty()){
int x = pq.top().fi;
int a, b, c, d;
tie(a, b, c, d) = pq.top().se; pq.pop();
if(dist[a][b][c][d] < x)continue;
if(a > b)continue;
if(!d){
int cur = (!d ? X[a - 1] : X[b + 1]);
int nxt = x + abs(cur - X[a]);
int tot = c + (nxt <= T[a]);
if(dist[a + 1][b][tot][0] > nxt){
dist[a + 1][b][tot][0] = nxt;
pq.push({nxt, {a + 1, b, tot, 0}});
}
nxt = x + min(abs(cur - X[b]), cur + l - X[b]);
tot = c + (nxt <= T[b]);
if(dist[a][b - 1][tot][1] > nxt){
dist[a][b - 1][tot][1] = nxt;
pq.push({nxt, {a, b - 1, tot, 1}});
}
}
else{
int cur = (!d ? X[a - 1] : X[b + 1]);
int nxt = x + min(l - cur + X[a], abs(cur - X[a]));
int tot = c + (nxt <= T[a]);
if(dist[a + 1][b][tot][0] > nxt){
dist[a + 1][b][tot][0] = nxt;
pq.push({nxt, {a + 1, b, tot, 0}});
}
nxt = x + min(abs(cur - X[b]), l - cur + l - X[b]);
tot = c + (nxt <= T[b]);
if(dist[a][b - 1][tot][1] > nxt){
dist[a][b - 1][tot][1] = nxt;
pq.push({nxt, {a, b - 1, tot, 1}});
}
}
}
int ans = 0;
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
for(int k = 1; k <= n; k++){
if(dist[i][j][k][0] < 1e18 || dist[i][j][k][1] < 1e18)ans = max(ans, k);
}
}
}
cout << ans;
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message
ho_t3.cpp:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
74 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
6608 KB |
Output is correct |
23 |
Correct |
1 ms |
10588 KB |
Output is correct |
24 |
Correct |
1 ms |
10588 KB |
Output is correct |
25 |
Correct |
1 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
1 ms |
6488 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10700 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
1 ms |
10748 KB |
Output is correct |
33 |
Correct |
2 ms |
10840 KB |
Output is correct |
34 |
Correct |
1 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
611 ms |
118892 KB |
Output is correct |
19 |
Correct |
291 ms |
78016 KB |
Output is correct |
20 |
Correct |
94 ms |
51148 KB |
Output is correct |
21 |
Correct |
230 ms |
74928 KB |
Output is correct |
22 |
Correct |
401 ms |
94644 KB |
Output is correct |
23 |
Correct |
105 ms |
47252 KB |
Output is correct |
24 |
Correct |
30 ms |
41296 KB |
Output is correct |
25 |
Correct |
90 ms |
46784 KB |
Output is correct |
26 |
Correct |
13 ms |
30616 KB |
Output is correct |
27 |
Correct |
107 ms |
45464 KB |
Output is correct |
28 |
Correct |
27 ms |
36760 KB |
Output is correct |
29 |
Correct |
92 ms |
44752 KB |
Output is correct |
30 |
Correct |
31 ms |
39504 KB |
Output is correct |
31 |
Correct |
82 ms |
43080 KB |
Output is correct |
32 |
Correct |
27 ms |
32848 KB |
Output is correct |
33 |
Correct |
76 ms |
43084 KB |
Output is correct |
34 |
Correct |
11 ms |
28732 KB |
Output is correct |
35 |
Correct |
28 ms |
41984 KB |
Output is correct |
36 |
Correct |
15 ms |
31124 KB |
Output is correct |
37 |
Correct |
34 ms |
43416 KB |
Output is correct |
38 |
Correct |
27 ms |
33872 KB |
Output is correct |
39 |
Correct |
35 ms |
44440 KB |
Output is correct |
40 |
Correct |
20 ms |
34456 KB |
Output is correct |
41 |
Correct |
1072 ms |
150528 KB |
Output is correct |
42 |
Correct |
46 ms |
92468 KB |
Output is correct |
43 |
Correct |
1050 ms |
150692 KB |
Output is correct |
44 |
Correct |
46 ms |
91536 KB |
Output is correct |
45 |
Correct |
1116 ms |
150696 KB |
Output is correct |
46 |
Correct |
46 ms |
92464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
6608 KB |
Output is correct |
23 |
Correct |
1 ms |
10588 KB |
Output is correct |
24 |
Correct |
1 ms |
10588 KB |
Output is correct |
25 |
Correct |
1 ms |
10588 KB |
Output is correct |
26 |
Correct |
2 ms |
10588 KB |
Output is correct |
27 |
Correct |
1 ms |
6488 KB |
Output is correct |
28 |
Correct |
1 ms |
6492 KB |
Output is correct |
29 |
Correct |
1 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10700 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
1 ms |
10748 KB |
Output is correct |
33 |
Correct |
2 ms |
10840 KB |
Output is correct |
34 |
Correct |
1 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
611 ms |
118892 KB |
Output is correct |
37 |
Correct |
291 ms |
78016 KB |
Output is correct |
38 |
Correct |
94 ms |
51148 KB |
Output is correct |
39 |
Correct |
230 ms |
74928 KB |
Output is correct |
40 |
Correct |
401 ms |
94644 KB |
Output is correct |
41 |
Correct |
105 ms |
47252 KB |
Output is correct |
42 |
Correct |
30 ms |
41296 KB |
Output is correct |
43 |
Correct |
90 ms |
46784 KB |
Output is correct |
44 |
Correct |
13 ms |
30616 KB |
Output is correct |
45 |
Correct |
107 ms |
45464 KB |
Output is correct |
46 |
Correct |
27 ms |
36760 KB |
Output is correct |
47 |
Correct |
92 ms |
44752 KB |
Output is correct |
48 |
Correct |
31 ms |
39504 KB |
Output is correct |
49 |
Correct |
82 ms |
43080 KB |
Output is correct |
50 |
Correct |
27 ms |
32848 KB |
Output is correct |
51 |
Correct |
76 ms |
43084 KB |
Output is correct |
52 |
Correct |
11 ms |
28732 KB |
Output is correct |
53 |
Correct |
28 ms |
41984 KB |
Output is correct |
54 |
Correct |
15 ms |
31124 KB |
Output is correct |
55 |
Correct |
34 ms |
43416 KB |
Output is correct |
56 |
Correct |
27 ms |
33872 KB |
Output is correct |
57 |
Correct |
35 ms |
44440 KB |
Output is correct |
58 |
Correct |
20 ms |
34456 KB |
Output is correct |
59 |
Correct |
1072 ms |
150528 KB |
Output is correct |
60 |
Correct |
46 ms |
92468 KB |
Output is correct |
61 |
Correct |
1050 ms |
150692 KB |
Output is correct |
62 |
Correct |
46 ms |
91536 KB |
Output is correct |
63 |
Correct |
1116 ms |
150696 KB |
Output is correct |
64 |
Correct |
46 ms |
92464 KB |
Output is correct |
65 |
Correct |
813 ms |
139240 KB |
Output is correct |
66 |
Correct |
682 ms |
130552 KB |
Output is correct |
67 |
Correct |
637 ms |
126376 KB |
Output is correct |
68 |
Correct |
508 ms |
108984 KB |
Output is correct |
69 |
Correct |
791 ms |
138232 KB |
Output is correct |
70 |
Correct |
834 ms |
133712 KB |
Output is correct |
71 |
Correct |
520 ms |
134752 KB |
Output is correct |
72 |
Correct |
897 ms |
135872 KB |
Output is correct |
73 |
Correct |
256 ms |
117940 KB |
Output is correct |
74 |
Correct |
648 ms |
112312 KB |
Output is correct |
75 |
Correct |
547 ms |
132024 KB |
Output is correct |
76 |
Correct |
926 ms |
136116 KB |
Output is correct |
77 |
Correct |
730 ms |
146344 KB |
Output is correct |
78 |
Correct |
574 ms |
105204 KB |
Output is correct |
79 |
Correct |
632 ms |
123868 KB |
Output is correct |
80 |
Correct |
909 ms |
133732 KB |
Output is correct |
81 |
Correct |
488 ms |
124936 KB |
Output is correct |
82 |
Correct |
341 ms |
119480 KB |
Output is correct |
83 |
Correct |
825 ms |
150940 KB |
Output is correct |
84 |
Correct |
380 ms |
123772 KB |
Output is correct |
85 |
Correct |
355 ms |
132400 KB |
Output is correct |
86 |
Correct |
425 ms |
129948 KB |
Output is correct |
87 |
Correct |
711 ms |
131748 KB |
Output is correct |
88 |
Correct |
1464 ms |
151716 KB |
Output is correct |
89 |
Correct |
1118 ms |
151816 KB |
Output is correct |
90 |
Correct |
57 ms |
112528 KB |
Output is correct |
91 |
Correct |
1473 ms |
151736 KB |
Output is correct |
92 |
Correct |
1080 ms |
151716 KB |
Output is correct |
93 |
Correct |
66 ms |
129420 KB |
Output is correct |