#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 200+10;
const ll INF = 1e18;
int n,l;
int dist[nax], tim[nax];
ll dp[nax][nax][nax][2];
int get_dist(int i, int j) {
return (i <= j ? dist[j] - dist[i] : l - dist[i] + dist[j]);
}
int main() {_
cin >> n >> l;
for(int i = 1; i <= n; ++i) {
cin >> dist[i];
}
for(int i = 1; i <= n; ++i) {
cin >> tim[i];
}
for(int i = 0; i <= n; ++i) {
for(int j = 0; j <= n; ++j) {
for(int k = 0; k <= n; ++k) {
dp[i][j][k][0] = dp[i][j][k][1] = INF;
}
}
}
dp[0][0][0][0] = 0;
dp[0][0][0][1] = 0;
int cur = 0; int cnt = 0;
int ans = 0;
for(int i = 1; i <= n; ++i) {
if(dist[i] <= tim[i]) {
cnt++;
}
dp[0][i][cnt][1] = dist[i];
dp[0][i][cnt][0] = 2 * dist[i];
ans = max(ans,cnt);
}
cnt = 0;
dist[n+1] = l;
for(int i = 1; i <= n; ++i) {
cur += dist[n-i+2] - dist[n-i+1];
if(cur <= tim[n - i + 1]) {
cnt++;
}
dp[i][0][cnt][0] = cur;
dp[i][0][cnt][1] = 2 * cur;
//cout << i << " " << cur << " " << cnt << "\n";
ans = max(ans,cnt);
}
for(int k = 0; k <= n; ++k) {
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
if(i + j > n || i + j < k) continue;
dp[i][j][k][0] = min({dp[i][j][k][0],dp[i-1][j][k][0] + get_dist(n - i + 1, n - i +2), dp[i-1][j][k][1] + get_dist(n - i + 1, j)});
dp[i][j][k][1] = min({dp[i][j][k][1],dp[i][j-1][k][1] + get_dist(j-1, j), dp[i][j-1][k][0] + get_dist(n-i+1, j)});
if(k > 0) {
if(tim[n - i + 1] >= min(dp[i-1][j][k][1] + get_dist(n - i + 1, j),dp[i-1][j][k][0] + get_dist(n - i + 1, n - i +2))) {
dp[i][j][k+1][0] = min(dp[i][j][k+1][0], min(dp[i-1][j][k][1] + get_dist(n - i + 1, j),dp[i-1][j][k][0] + get_dist(n - i + 1, n - i +2)));
}
if(tim[j] >= min(dp[i][j-1][k][1] + get_dist(j-1, j), dp[i][j-1][k][0] + get_dist(n-i+1, j))) {
dp[i][j][k+1][1] = min(dp[i][j][k+1][1], min(dp[i][j-1][k][1] + get_dist(j-1, j), dp[i][j-1][k][0] + get_dist(n-i+1, j)));
}
if(dp[i][j][k][0] < INF || dp[i][j][k][1] < INF) {
ans = max(ans,k);
}
}
}
}
}
//~ for(int i = 0; i <= n; ++i) {
//~ for(int j = 0; j <= n; ++j) {
//~ for(int k = 0; k <= n; ++k) {
//~ if(i + j > n || i + j < k) continue;
//~ for(int o : {0,1}) {
//~ cout << "[" << i << " " << j << " " << k << " " << o << "] : " << (dp[i][j][k][o] != INF ? dp[i][j][k][o] : -1) << "\n";
//~ }
//~ }
//~ }
//~ }
cout << ans;
}
Compilation message
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:21:17: warning: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Wstrict-overflow]
return (i <= j ? dist[j] - dist[i] : l - dist[i] + dist[j]);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:21:17: warning: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Wstrict-overflow]
return (i <= j ? dist[j] - dist[i] : l - dist[i] + dist[j]);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:21:17: warning: assuming signed overflow does not occur when assuming that (X - c) <= X is always true [-Wstrict-overflow]
return (i <= j ? dist[j] - dist[i] : l - dist[i] + dist[j]);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:21:17: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow]
return (i <= j ? dist[j] - dist[i] : l - dist[i] + dist[j]);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:21:17: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow]
return (i <= j ? dist[j] - dist[i] : l - dist[i] + dist[j]);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:21:17: warning: assuming signed overflow does not occur when assuming that (X + c) >= X is always true [-Wstrict-overflow]
return (i <= j ? dist[j] - dist[i] : l - dist[i] + dist[j]);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
1152 KB |
Output is correct |
19 |
Correct |
5 ms |
768 KB |
Output is correct |
20 |
Correct |
5 ms |
896 KB |
Output is correct |
21 |
Correct |
5 ms |
1152 KB |
Output is correct |
22 |
Correct |
5 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
1280 KB |
Output is correct |
24 |
Correct |
5 ms |
1024 KB |
Output is correct |
25 |
Correct |
5 ms |
1152 KB |
Output is correct |
26 |
Correct |
5 ms |
1024 KB |
Output is correct |
27 |
Correct |
5 ms |
640 KB |
Output is correct |
28 |
Correct |
5 ms |
640 KB |
Output is correct |
29 |
Correct |
5 ms |
1152 KB |
Output is correct |
30 |
Correct |
5 ms |
1280 KB |
Output is correct |
31 |
Correct |
5 ms |
1152 KB |
Output is correct |
32 |
Correct |
5 ms |
1024 KB |
Output is correct |
33 |
Correct |
5 ms |
1280 KB |
Output is correct |
34 |
Correct |
5 ms |
1152 KB |
Output is correct |
35 |
Correct |
5 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
896 KB |
Output is correct |
18 |
Correct |
97 ms |
107512 KB |
Output is correct |
19 |
Correct |
54 ms |
65280 KB |
Output is correct |
20 |
Correct |
28 ms |
34816 KB |
Output is correct |
21 |
Correct |
53 ms |
61560 KB |
Output is correct |
22 |
Correct |
70 ms |
79992 KB |
Output is correct |
23 |
Correct |
25 ms |
29696 KB |
Output is correct |
24 |
Correct |
20 ms |
23168 KB |
Output is correct |
25 |
Correct |
25 ms |
29056 KB |
Output is correct |
26 |
Correct |
11 ms |
11136 KB |
Output is correct |
27 |
Correct |
26 ms |
30336 KB |
Output is correct |
28 |
Correct |
18 ms |
21632 KB |
Output is correct |
29 |
Correct |
25 ms |
30976 KB |
Output is correct |
30 |
Correct |
20 ms |
24320 KB |
Output is correct |
31 |
Correct |
24 ms |
29056 KB |
Output is correct |
32 |
Correct |
13 ms |
15360 KB |
Output is correct |
33 |
Correct |
24 ms |
29056 KB |
Output is correct |
34 |
Correct |
10 ms |
10368 KB |
Output is correct |
35 |
Correct |
22 ms |
28416 KB |
Output is correct |
36 |
Correct |
13 ms |
13568 KB |
Output is correct |
37 |
Correct |
24 ms |
30336 KB |
Output is correct |
38 |
Correct |
15 ms |
16640 KB |
Output is correct |
39 |
Correct |
26 ms |
31608 KB |
Output is correct |
40 |
Correct |
16 ms |
18560 KB |
Output is correct |
41 |
Correct |
126 ms |
132600 KB |
Output is correct |
42 |
Correct |
75 ms |
89336 KB |
Output is correct |
43 |
Correct |
132 ms |
132600 KB |
Output is correct |
44 |
Correct |
75 ms |
88312 KB |
Output is correct |
45 |
Correct |
123 ms |
132600 KB |
Output is correct |
46 |
Correct |
75 ms |
89336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
896 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
768 KB |
Output is correct |
9 |
Correct |
5 ms |
896 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
896 KB |
Output is correct |
17 |
Correct |
5 ms |
896 KB |
Output is correct |
18 |
Correct |
5 ms |
1152 KB |
Output is correct |
19 |
Correct |
5 ms |
768 KB |
Output is correct |
20 |
Correct |
5 ms |
896 KB |
Output is correct |
21 |
Correct |
5 ms |
1152 KB |
Output is correct |
22 |
Correct |
5 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
1280 KB |
Output is correct |
24 |
Correct |
5 ms |
1024 KB |
Output is correct |
25 |
Correct |
5 ms |
1152 KB |
Output is correct |
26 |
Correct |
5 ms |
1024 KB |
Output is correct |
27 |
Correct |
5 ms |
640 KB |
Output is correct |
28 |
Correct |
5 ms |
640 KB |
Output is correct |
29 |
Correct |
5 ms |
1152 KB |
Output is correct |
30 |
Correct |
5 ms |
1280 KB |
Output is correct |
31 |
Correct |
5 ms |
1152 KB |
Output is correct |
32 |
Correct |
5 ms |
1024 KB |
Output is correct |
33 |
Correct |
5 ms |
1280 KB |
Output is correct |
34 |
Correct |
5 ms |
1152 KB |
Output is correct |
35 |
Correct |
5 ms |
1152 KB |
Output is correct |
36 |
Correct |
97 ms |
107512 KB |
Output is correct |
37 |
Correct |
54 ms |
65280 KB |
Output is correct |
38 |
Correct |
28 ms |
34816 KB |
Output is correct |
39 |
Correct |
53 ms |
61560 KB |
Output is correct |
40 |
Correct |
70 ms |
79992 KB |
Output is correct |
41 |
Correct |
25 ms |
29696 KB |
Output is correct |
42 |
Correct |
20 ms |
23168 KB |
Output is correct |
43 |
Correct |
25 ms |
29056 KB |
Output is correct |
44 |
Correct |
11 ms |
11136 KB |
Output is correct |
45 |
Correct |
26 ms |
30336 KB |
Output is correct |
46 |
Correct |
18 ms |
21632 KB |
Output is correct |
47 |
Correct |
25 ms |
30976 KB |
Output is correct |
48 |
Correct |
20 ms |
24320 KB |
Output is correct |
49 |
Correct |
24 ms |
29056 KB |
Output is correct |
50 |
Correct |
13 ms |
15360 KB |
Output is correct |
51 |
Correct |
24 ms |
29056 KB |
Output is correct |
52 |
Correct |
10 ms |
10368 KB |
Output is correct |
53 |
Correct |
22 ms |
28416 KB |
Output is correct |
54 |
Correct |
13 ms |
13568 KB |
Output is correct |
55 |
Correct |
24 ms |
30336 KB |
Output is correct |
56 |
Correct |
15 ms |
16640 KB |
Output is correct |
57 |
Correct |
26 ms |
31608 KB |
Output is correct |
58 |
Correct |
16 ms |
18560 KB |
Output is correct |
59 |
Correct |
126 ms |
132600 KB |
Output is correct |
60 |
Correct |
75 ms |
89336 KB |
Output is correct |
61 |
Correct |
132 ms |
132600 KB |
Output is correct |
62 |
Correct |
75 ms |
88312 KB |
Output is correct |
63 |
Correct |
123 ms |
132600 KB |
Output is correct |
64 |
Correct |
75 ms |
89336 KB |
Output is correct |
65 |
Correct |
111 ms |
119676 KB |
Output is correct |
66 |
Correct |
104 ms |
110072 KB |
Output is correct |
67 |
Correct |
93 ms |
105208 KB |
Output is correct |
68 |
Correct |
86 ms |
97144 KB |
Output is correct |
69 |
Correct |
106 ms |
118520 KB |
Output is correct |
70 |
Correct |
108 ms |
113656 KB |
Output is correct |
71 |
Correct |
107 ms |
114724 KB |
Output is correct |
72 |
Correct |
105 ms |
116216 KB |
Output is correct |
73 |
Correct |
97 ms |
107512 KB |
Output is correct |
74 |
Correct |
91 ms |
100472 KB |
Output is correct |
75 |
Correct |
98 ms |
111096 KB |
Output is correct |
76 |
Correct |
121 ms |
127552 KB |
Output is correct |
77 |
Correct |
116 ms |
127352 KB |
Output is correct |
78 |
Correct |
88 ms |
98168 KB |
Output is correct |
79 |
Correct |
86 ms |
101624 KB |
Output is correct |
80 |
Correct |
117 ms |
124872 KB |
Output is correct |
81 |
Correct |
89 ms |
102904 KB |
Output is correct |
82 |
Correct |
98 ms |
108792 KB |
Output is correct |
83 |
Correct |
121 ms |
132600 KB |
Output is correct |
84 |
Correct |
107 ms |
113528 KB |
Output is correct |
85 |
Correct |
111 ms |
123596 KB |
Output is correct |
86 |
Correct |
111 ms |
121080 KB |
Output is correct |
87 |
Correct |
100 ms |
111096 KB |
Output is correct |
88 |
Correct |
130 ms |
133880 KB |
Output is correct |
89 |
Correct |
138 ms |
134008 KB |
Output is correct |
90 |
Correct |
97 ms |
112376 KB |
Output is correct |
91 |
Correct |
129 ms |
133964 KB |
Output is correct |
92 |
Correct |
126 ms |
133992 KB |
Output is correct |
93 |
Correct |
120 ms |
131320 KB |
Output is correct |