#include <bits/stdc++.h>
using namespace std;
int N, L;
long long dp[2][205][205][205];
//bool vis[2][205][205][205];
long long arr[205], brr[205];
void relax(int cw,int ccw, int k){
long long d = dp[0][cw][ccw][k]+arr[cw+1]-arr[cw];
bool kk = (d <= brr[cw+1]);
assert(d >= 0);
dp[0][cw+1][ccw][k+kk] = min(dp[0][cw+1][ccw][k+kk], d);
d = dp[1][cw][ccw][k] + L-arr[ccw] + arr[cw+1];
kk = (d <= brr[cw+1]);
assert(d >= 0);
dp[0][cw+1][ccw][k+kk] = min(dp[0][cw+1][ccw][k+kk], d);
d = dp[0][cw][ccw][k] + arr[cw] + L-arr[ccw-1];
kk = (d <= brr[ccw-1]);
assert(d >= 0);
dp[1][cw][ccw-1][k+kk] = min(dp[1][cw][ccw-1][k+kk], d);
d = dp[1][cw][ccw][k] + arr[ccw] - arr[ccw-1];
kk = (d <= brr[ccw-1]);
assert(d >= 0);
dp[1][cw][ccw-1][k+kk] = min(dp[1][cw][ccw-1][k+kk], d);
}
int main(){
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> L;
for(int i = 1; i<=N; i++){
cin >> arr[i];
}
for(int i = 1; i<=N; i++){
cin >> brr[i];
}
for(int cw = 0; cw<=N; cw++){
for(int ccw = N+1; ccw>cw; ccw--){
for(int k = 0; k<=N; k++){
dp[0][cw][ccw][k] = dp[1][cw][ccw][k] = LLONG_MAX/4;
}
}
}
dp[0][0][N+1][0] = 0; //sd = 0 means cw
arr[N+1] = L;
for(int cw = 0; cw<=N; cw++){
for(int ccw = N+1; ccw>cw+1; ccw--){
for(int k = 0; k<=N; k++){
relax(cw, ccw, k);
}
}
}
int ans = 0;
for(int k = 0; k<=N; k++){
for(int cw = 0; cw<=N; cw++){
for(int ccw = N+1; ccw>cw; ccw--){
if(dp[0][cw][ccw][k] != LLONG_MAX/4){
ans = max(ans, k);
}
if(dp[1][cw][ccw][k] != LLONG_MAX/4){
ans = max(ans, k);
}
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
636 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
4 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
760 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
760 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
760 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
760 KB |
Output is correct |
17 |
Correct |
5 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
636 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
4 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
760 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
760 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
760 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
760 KB |
Output is correct |
17 |
Correct |
5 ms |
760 KB |
Output is correct |
18 |
Correct |
5 ms |
760 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
5 ms |
760 KB |
Output is correct |
21 |
Correct |
5 ms |
760 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
888 KB |
Output is correct |
24 |
Correct |
5 ms |
764 KB |
Output is correct |
25 |
Correct |
5 ms |
764 KB |
Output is correct |
26 |
Correct |
5 ms |
940 KB |
Output is correct |
27 |
Correct |
5 ms |
504 KB |
Output is correct |
28 |
Correct |
5 ms |
632 KB |
Output is correct |
29 |
Correct |
5 ms |
888 KB |
Output is correct |
30 |
Correct |
5 ms |
888 KB |
Output is correct |
31 |
Correct |
5 ms |
888 KB |
Output is correct |
32 |
Correct |
5 ms |
764 KB |
Output is correct |
33 |
Correct |
5 ms |
888 KB |
Output is correct |
34 |
Correct |
5 ms |
892 KB |
Output is correct |
35 |
Correct |
5 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
636 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
4 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
760 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
760 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
760 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
760 KB |
Output is correct |
17 |
Correct |
5 ms |
760 KB |
Output is correct |
18 |
Correct |
153 ms |
54136 KB |
Output is correct |
19 |
Correct |
77 ms |
33144 KB |
Output is correct |
20 |
Correct |
36 ms |
17912 KB |
Output is correct |
21 |
Correct |
75 ms |
31352 KB |
Output is correct |
22 |
Correct |
102 ms |
40312 KB |
Output is correct |
23 |
Correct |
30 ms |
15224 KB |
Output is correct |
24 |
Correct |
22 ms |
12152 KB |
Output is correct |
25 |
Correct |
29 ms |
15096 KB |
Output is correct |
26 |
Correct |
11 ms |
6008 KB |
Output is correct |
27 |
Correct |
30 ms |
15608 KB |
Output is correct |
28 |
Correct |
22 ms |
11256 KB |
Output is correct |
29 |
Correct |
30 ms |
15992 KB |
Output is correct |
30 |
Correct |
24 ms |
12664 KB |
Output is correct |
31 |
Correct |
29 ms |
15096 KB |
Output is correct |
32 |
Correct |
15 ms |
8056 KB |
Output is correct |
33 |
Correct |
29 ms |
15096 KB |
Output is correct |
34 |
Correct |
10 ms |
5628 KB |
Output is correct |
35 |
Correct |
28 ms |
14712 KB |
Output is correct |
36 |
Correct |
13 ms |
7288 KB |
Output is correct |
37 |
Correct |
30 ms |
15608 KB |
Output is correct |
38 |
Correct |
16 ms |
8824 KB |
Output is correct |
39 |
Correct |
32 ms |
16248 KB |
Output is correct |
40 |
Correct |
18 ms |
9720 KB |
Output is correct |
41 |
Correct |
205 ms |
66552 KB |
Output is correct |
42 |
Correct |
118 ms |
45048 KB |
Output is correct |
43 |
Correct |
206 ms |
66552 KB |
Output is correct |
44 |
Correct |
115 ms |
44536 KB |
Output is correct |
45 |
Correct |
200 ms |
66552 KB |
Output is correct |
46 |
Correct |
118 ms |
45180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
636 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
4 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
760 KB |
Output is correct |
7 |
Correct |
5 ms |
504 KB |
Output is correct |
8 |
Correct |
5 ms |
632 KB |
Output is correct |
9 |
Correct |
5 ms |
760 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
760 KB |
Output is correct |
13 |
Correct |
5 ms |
760 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
760 KB |
Output is correct |
17 |
Correct |
5 ms |
760 KB |
Output is correct |
18 |
Correct |
5 ms |
760 KB |
Output is correct |
19 |
Correct |
5 ms |
632 KB |
Output is correct |
20 |
Correct |
5 ms |
760 KB |
Output is correct |
21 |
Correct |
5 ms |
760 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
888 KB |
Output is correct |
24 |
Correct |
5 ms |
764 KB |
Output is correct |
25 |
Correct |
5 ms |
764 KB |
Output is correct |
26 |
Correct |
5 ms |
940 KB |
Output is correct |
27 |
Correct |
5 ms |
504 KB |
Output is correct |
28 |
Correct |
5 ms |
632 KB |
Output is correct |
29 |
Correct |
5 ms |
888 KB |
Output is correct |
30 |
Correct |
5 ms |
888 KB |
Output is correct |
31 |
Correct |
5 ms |
888 KB |
Output is correct |
32 |
Correct |
5 ms |
764 KB |
Output is correct |
33 |
Correct |
5 ms |
888 KB |
Output is correct |
34 |
Correct |
5 ms |
892 KB |
Output is correct |
35 |
Correct |
5 ms |
888 KB |
Output is correct |
36 |
Correct |
153 ms |
54136 KB |
Output is correct |
37 |
Correct |
77 ms |
33144 KB |
Output is correct |
38 |
Correct |
36 ms |
17912 KB |
Output is correct |
39 |
Correct |
75 ms |
31352 KB |
Output is correct |
40 |
Correct |
102 ms |
40312 KB |
Output is correct |
41 |
Correct |
30 ms |
15224 KB |
Output is correct |
42 |
Correct |
22 ms |
12152 KB |
Output is correct |
43 |
Correct |
29 ms |
15096 KB |
Output is correct |
44 |
Correct |
11 ms |
6008 KB |
Output is correct |
45 |
Correct |
30 ms |
15608 KB |
Output is correct |
46 |
Correct |
22 ms |
11256 KB |
Output is correct |
47 |
Correct |
30 ms |
15992 KB |
Output is correct |
48 |
Correct |
24 ms |
12664 KB |
Output is correct |
49 |
Correct |
29 ms |
15096 KB |
Output is correct |
50 |
Correct |
15 ms |
8056 KB |
Output is correct |
51 |
Correct |
29 ms |
15096 KB |
Output is correct |
52 |
Correct |
10 ms |
5628 KB |
Output is correct |
53 |
Correct |
28 ms |
14712 KB |
Output is correct |
54 |
Correct |
13 ms |
7288 KB |
Output is correct |
55 |
Correct |
30 ms |
15608 KB |
Output is correct |
56 |
Correct |
16 ms |
8824 KB |
Output is correct |
57 |
Correct |
32 ms |
16248 KB |
Output is correct |
58 |
Correct |
18 ms |
9720 KB |
Output is correct |
59 |
Correct |
205 ms |
66552 KB |
Output is correct |
60 |
Correct |
118 ms |
45048 KB |
Output is correct |
61 |
Correct |
206 ms |
66552 KB |
Output is correct |
62 |
Correct |
115 ms |
44536 KB |
Output is correct |
63 |
Correct |
200 ms |
66552 KB |
Output is correct |
64 |
Correct |
118 ms |
45180 KB |
Output is correct |
65 |
Correct |
180 ms |
60152 KB |
Output is correct |
66 |
Correct |
152 ms |
55416 KB |
Output is correct |
67 |
Correct |
141 ms |
52984 KB |
Output is correct |
68 |
Correct |
134 ms |
48888 KB |
Output is correct |
69 |
Correct |
177 ms |
59640 KB |
Output is correct |
70 |
Correct |
165 ms |
57080 KB |
Output is correct |
71 |
Correct |
168 ms |
57720 KB |
Output is correct |
72 |
Correct |
173 ms |
58488 KB |
Output is correct |
73 |
Correct |
153 ms |
54136 KB |
Output is correct |
74 |
Correct |
136 ms |
50680 KB |
Output is correct |
75 |
Correct |
159 ms |
55928 KB |
Output is correct |
76 |
Correct |
198 ms |
64120 KB |
Output is correct |
77 |
Correct |
194 ms |
64120 KB |
Output is correct |
78 |
Correct |
135 ms |
49528 KB |
Output is correct |
79 |
Correct |
140 ms |
51192 KB |
Output is correct |
80 |
Correct |
188 ms |
62712 KB |
Output is correct |
81 |
Correct |
144 ms |
51912 KB |
Output is correct |
82 |
Correct |
155 ms |
54648 KB |
Output is correct |
83 |
Correct |
211 ms |
66612 KB |
Output is correct |
84 |
Correct |
168 ms |
57208 KB |
Output is correct |
85 |
Correct |
178 ms |
62072 KB |
Output is correct |
86 |
Correct |
181 ms |
60920 KB |
Output is correct |
87 |
Correct |
161 ms |
55804 KB |
Output is correct |
88 |
Correct |
206 ms |
67192 KB |
Output is correct |
89 |
Correct |
217 ms |
67320 KB |
Output is correct |
90 |
Correct |
161 ms |
56568 KB |
Output is correct |
91 |
Correct |
206 ms |
67192 KB |
Output is correct |
92 |
Correct |
209 ms |
67192 KB |
Output is correct |
93 |
Correct |
203 ms |
65912 KB |
Output is correct |