#include<bits/stdc++.h>
using namespace std;
const int MX = 203;
const int INF = 1e9+10;
int n, L;
int pos[MX], T[MX];
int dp[MX][MX][MX];
int dist(int i, int j) {
int ret = abs(pos[i]-pos[j]);
return min(ret, L-ret);
}
int solve(int i, int j, int k) {
if(k==0) return dist(0, i);
if(n-(abs(j-i)-1)<k) return INF;
int &ret = dp[i][j][k];
if(ret!=-1) return ret;
ret = INF;
if(i<=j) {
if(i>1) {
if(solve(i-1, j, k-1)+dist(i, i-1)<=T[i]) {
ret = min(ret, solve(i-1, j, k-1)+dist(i, i-1));
}
if(solve(i-1, j, k)!=INF) {
ret = min(ret, solve(i-1, j, k)+dist(i, i-1));
}
} else {
if(j==n && dist(0, i)<=T[i] && k==1) {
ret = min(ret, dist(0, i));
}
}
if(j+1<=n) {
if(solve(j+1, i, k-1)+dist(j+1, i)<=T[i]) {
ret = min(ret, solve(j+1, i, k-1)+dist(j+1, i));
}
if(solve(j+1, i, k)!=INF) {
ret = min(ret, solve(j+1, i, k)+dist(j+1, i));
}
}
} else {
if(i+1<=n) {
if(solve(i+1, j, k-1)+dist(i, i+1)<=T[i]) {
ret = min(ret, solve(i+1, j, k-1)+dist(i, i+1));
}
if(solve(i+1, j, k)!=INF) {
ret = min(ret, solve(i+1, j, k)+dist(i, i+1));
}
}
if(j>1) {
if(solve(j-1, i, k-1)+dist(i, j-1)<=T[i]) {
ret = min(ret, solve(j-1, i, k-1)+dist(i, j-1));
}
if(solve(j-1, i, k)!=INF) {
ret = min(ret, solve(j-1, i, k)+dist(i, j-1));
}
} else {
if(i==n && dist(0, i)<=T[i] && k==1) {
ret = min(ret, dist(0, i));
}
}
}
return ret;
}
void PlayGround() {
cin>>n>>L;
for(int i=1; i<=n; ++i) {
cin>>pos[i];
}
for(int i=1; i<=n; ++i) {
cin>>T[i];
}
memset(dp, -1, sizeof dp);
int ans = 0;
for(int i=1; i<=n; ++i) {
for(int j=1; j<=n; ++j) {
for(int k=1; k<=n; ++k) {
if(solve(i, j, k)<INF) {
ans = max(ans, k);
}
}
}
}
cout<<ans<<'\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
PlayGround();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
33000 KB |
Output is correct |
2 |
Correct |
15 ms |
32980 KB |
Output is correct |
3 |
Correct |
14 ms |
33000 KB |
Output is correct |
4 |
Correct |
14 ms |
32992 KB |
Output is correct |
5 |
Correct |
12 ms |
32980 KB |
Output is correct |
6 |
Correct |
14 ms |
33044 KB |
Output is correct |
7 |
Correct |
14 ms |
32976 KB |
Output is correct |
8 |
Correct |
14 ms |
33108 KB |
Output is correct |
9 |
Correct |
14 ms |
32980 KB |
Output is correct |
10 |
Correct |
14 ms |
32980 KB |
Output is correct |
11 |
Correct |
15 ms |
33028 KB |
Output is correct |
12 |
Correct |
13 ms |
32972 KB |
Output is correct |
13 |
Correct |
14 ms |
33036 KB |
Output is correct |
14 |
Correct |
13 ms |
32968 KB |
Output is correct |
15 |
Correct |
13 ms |
32980 KB |
Output is correct |
16 |
Correct |
16 ms |
33044 KB |
Output is correct |
17 |
Correct |
14 ms |
32968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
33000 KB |
Output is correct |
2 |
Correct |
15 ms |
32980 KB |
Output is correct |
3 |
Correct |
14 ms |
33000 KB |
Output is correct |
4 |
Correct |
14 ms |
32992 KB |
Output is correct |
5 |
Correct |
12 ms |
32980 KB |
Output is correct |
6 |
Correct |
14 ms |
33044 KB |
Output is correct |
7 |
Correct |
14 ms |
32976 KB |
Output is correct |
8 |
Correct |
14 ms |
33108 KB |
Output is correct |
9 |
Correct |
14 ms |
32980 KB |
Output is correct |
10 |
Correct |
14 ms |
32980 KB |
Output is correct |
11 |
Correct |
15 ms |
33028 KB |
Output is correct |
12 |
Correct |
13 ms |
32972 KB |
Output is correct |
13 |
Correct |
14 ms |
33036 KB |
Output is correct |
14 |
Correct |
13 ms |
32968 KB |
Output is correct |
15 |
Correct |
13 ms |
32980 KB |
Output is correct |
16 |
Correct |
16 ms |
33044 KB |
Output is correct |
17 |
Correct |
14 ms |
32968 KB |
Output is correct |
18 |
Correct |
14 ms |
33040 KB |
Output is correct |
19 |
Correct |
14 ms |
32980 KB |
Output is correct |
20 |
Correct |
14 ms |
32980 KB |
Output is correct |
21 |
Correct |
13 ms |
32964 KB |
Output is correct |
22 |
Correct |
17 ms |
32980 KB |
Output is correct |
23 |
Correct |
14 ms |
32964 KB |
Output is correct |
24 |
Correct |
13 ms |
32980 KB |
Output is correct |
25 |
Correct |
14 ms |
32980 KB |
Output is correct |
26 |
Correct |
13 ms |
32980 KB |
Output is correct |
27 |
Correct |
13 ms |
32964 KB |
Output is correct |
28 |
Correct |
13 ms |
32964 KB |
Output is correct |
29 |
Correct |
13 ms |
33064 KB |
Output is correct |
30 |
Correct |
17 ms |
32952 KB |
Output is correct |
31 |
Correct |
14 ms |
32980 KB |
Output is correct |
32 |
Correct |
14 ms |
32980 KB |
Output is correct |
33 |
Correct |
14 ms |
32980 KB |
Output is correct |
34 |
Correct |
13 ms |
32980 KB |
Output is correct |
35 |
Correct |
14 ms |
33048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
33000 KB |
Output is correct |
2 |
Correct |
15 ms |
32980 KB |
Output is correct |
3 |
Correct |
14 ms |
33000 KB |
Output is correct |
4 |
Correct |
14 ms |
32992 KB |
Output is correct |
5 |
Correct |
12 ms |
32980 KB |
Output is correct |
6 |
Correct |
14 ms |
33044 KB |
Output is correct |
7 |
Correct |
14 ms |
32976 KB |
Output is correct |
8 |
Correct |
14 ms |
33108 KB |
Output is correct |
9 |
Correct |
14 ms |
32980 KB |
Output is correct |
10 |
Correct |
14 ms |
32980 KB |
Output is correct |
11 |
Correct |
15 ms |
33028 KB |
Output is correct |
12 |
Correct |
13 ms |
32972 KB |
Output is correct |
13 |
Correct |
14 ms |
33036 KB |
Output is correct |
14 |
Correct |
13 ms |
32968 KB |
Output is correct |
15 |
Correct |
13 ms |
32980 KB |
Output is correct |
16 |
Correct |
16 ms |
33044 KB |
Output is correct |
17 |
Correct |
14 ms |
32968 KB |
Output is correct |
18 |
Correct |
161 ms |
33056 KB |
Output is correct |
19 |
Correct |
95 ms |
33048 KB |
Output is correct |
20 |
Correct |
44 ms |
32944 KB |
Output is correct |
21 |
Correct |
85 ms |
33000 KB |
Output is correct |
22 |
Correct |
122 ms |
33052 KB |
Output is correct |
23 |
Correct |
41 ms |
32980 KB |
Output is correct |
24 |
Correct |
27 ms |
32980 KB |
Output is correct |
25 |
Correct |
40 ms |
33044 KB |
Output is correct |
26 |
Correct |
18 ms |
32948 KB |
Output is correct |
27 |
Correct |
42 ms |
32988 KB |
Output is correct |
28 |
Correct |
25 ms |
32980 KB |
Output is correct |
29 |
Correct |
40 ms |
32980 KB |
Output is correct |
30 |
Correct |
28 ms |
33052 KB |
Output is correct |
31 |
Correct |
37 ms |
33060 KB |
Output is correct |
32 |
Correct |
21 ms |
33004 KB |
Output is correct |
33 |
Correct |
38 ms |
32936 KB |
Output is correct |
34 |
Correct |
17 ms |
33020 KB |
Output is correct |
35 |
Correct |
30 ms |
32980 KB |
Output is correct |
36 |
Correct |
21 ms |
33028 KB |
Output is correct |
37 |
Correct |
31 ms |
32980 KB |
Output is correct |
38 |
Correct |
26 ms |
33080 KB |
Output is correct |
39 |
Correct |
32 ms |
32980 KB |
Output is correct |
40 |
Correct |
22 ms |
32980 KB |
Output is correct |
41 |
Correct |
254 ms |
33064 KB |
Output is correct |
42 |
Correct |
90 ms |
33068 KB |
Output is correct |
43 |
Correct |
245 ms |
33060 KB |
Output is correct |
44 |
Correct |
93 ms |
33068 KB |
Output is correct |
45 |
Correct |
247 ms |
33032 KB |
Output is correct |
46 |
Correct |
91 ms |
33052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
33000 KB |
Output is correct |
2 |
Correct |
15 ms |
32980 KB |
Output is correct |
3 |
Correct |
14 ms |
33000 KB |
Output is correct |
4 |
Correct |
14 ms |
32992 KB |
Output is correct |
5 |
Correct |
12 ms |
32980 KB |
Output is correct |
6 |
Correct |
14 ms |
33044 KB |
Output is correct |
7 |
Correct |
14 ms |
32976 KB |
Output is correct |
8 |
Correct |
14 ms |
33108 KB |
Output is correct |
9 |
Correct |
14 ms |
32980 KB |
Output is correct |
10 |
Correct |
14 ms |
32980 KB |
Output is correct |
11 |
Correct |
15 ms |
33028 KB |
Output is correct |
12 |
Correct |
13 ms |
32972 KB |
Output is correct |
13 |
Correct |
14 ms |
33036 KB |
Output is correct |
14 |
Correct |
13 ms |
32968 KB |
Output is correct |
15 |
Correct |
13 ms |
32980 KB |
Output is correct |
16 |
Correct |
16 ms |
33044 KB |
Output is correct |
17 |
Correct |
14 ms |
32968 KB |
Output is correct |
18 |
Correct |
14 ms |
33040 KB |
Output is correct |
19 |
Correct |
14 ms |
32980 KB |
Output is correct |
20 |
Correct |
14 ms |
32980 KB |
Output is correct |
21 |
Correct |
13 ms |
32964 KB |
Output is correct |
22 |
Correct |
17 ms |
32980 KB |
Output is correct |
23 |
Correct |
14 ms |
32964 KB |
Output is correct |
24 |
Correct |
13 ms |
32980 KB |
Output is correct |
25 |
Correct |
14 ms |
32980 KB |
Output is correct |
26 |
Correct |
13 ms |
32980 KB |
Output is correct |
27 |
Correct |
13 ms |
32964 KB |
Output is correct |
28 |
Correct |
13 ms |
32964 KB |
Output is correct |
29 |
Correct |
13 ms |
33064 KB |
Output is correct |
30 |
Correct |
17 ms |
32952 KB |
Output is correct |
31 |
Correct |
14 ms |
32980 KB |
Output is correct |
32 |
Correct |
14 ms |
32980 KB |
Output is correct |
33 |
Correct |
14 ms |
32980 KB |
Output is correct |
34 |
Correct |
13 ms |
32980 KB |
Output is correct |
35 |
Correct |
14 ms |
33048 KB |
Output is correct |
36 |
Correct |
161 ms |
33056 KB |
Output is correct |
37 |
Correct |
95 ms |
33048 KB |
Output is correct |
38 |
Correct |
44 ms |
32944 KB |
Output is correct |
39 |
Correct |
85 ms |
33000 KB |
Output is correct |
40 |
Correct |
122 ms |
33052 KB |
Output is correct |
41 |
Correct |
41 ms |
32980 KB |
Output is correct |
42 |
Correct |
27 ms |
32980 KB |
Output is correct |
43 |
Correct |
40 ms |
33044 KB |
Output is correct |
44 |
Correct |
18 ms |
32948 KB |
Output is correct |
45 |
Correct |
42 ms |
32988 KB |
Output is correct |
46 |
Correct |
25 ms |
32980 KB |
Output is correct |
47 |
Correct |
40 ms |
32980 KB |
Output is correct |
48 |
Correct |
28 ms |
33052 KB |
Output is correct |
49 |
Correct |
37 ms |
33060 KB |
Output is correct |
50 |
Correct |
21 ms |
33004 KB |
Output is correct |
51 |
Correct |
38 ms |
32936 KB |
Output is correct |
52 |
Correct |
17 ms |
33020 KB |
Output is correct |
53 |
Correct |
30 ms |
32980 KB |
Output is correct |
54 |
Correct |
21 ms |
33028 KB |
Output is correct |
55 |
Correct |
31 ms |
32980 KB |
Output is correct |
56 |
Correct |
26 ms |
33080 KB |
Output is correct |
57 |
Correct |
32 ms |
32980 KB |
Output is correct |
58 |
Correct |
22 ms |
32980 KB |
Output is correct |
59 |
Correct |
254 ms |
33064 KB |
Output is correct |
60 |
Correct |
90 ms |
33068 KB |
Output is correct |
61 |
Correct |
245 ms |
33060 KB |
Output is correct |
62 |
Correct |
93 ms |
33068 KB |
Output is correct |
63 |
Correct |
247 ms |
33032 KB |
Output is correct |
64 |
Correct |
91 ms |
33052 KB |
Output is correct |
65 |
Correct |
192 ms |
33064 KB |
Output is correct |
66 |
Correct |
177 ms |
33064 KB |
Output is correct |
67 |
Correct |
169 ms |
33064 KB |
Output is correct |
68 |
Correct |
138 ms |
33060 KB |
Output is correct |
69 |
Correct |
197 ms |
33060 KB |
Output is correct |
70 |
Correct |
224 ms |
33064 KB |
Output is correct |
71 |
Correct |
159 ms |
33060 KB |
Output is correct |
72 |
Correct |
233 ms |
33064 KB |
Output is correct |
73 |
Correct |
141 ms |
33064 KB |
Output is correct |
74 |
Correct |
190 ms |
33120 KB |
Output is correct |
75 |
Correct |
152 ms |
33064 KB |
Output is correct |
76 |
Correct |
258 ms |
33068 KB |
Output is correct |
77 |
Correct |
187 ms |
33064 KB |
Output is correct |
78 |
Correct |
172 ms |
32980 KB |
Output is correct |
79 |
Correct |
145 ms |
33064 KB |
Output is correct |
80 |
Correct |
246 ms |
32968 KB |
Output is correct |
81 |
Correct |
136 ms |
33064 KB |
Output is correct |
82 |
Correct |
151 ms |
33060 KB |
Output is correct |
83 |
Correct |
203 ms |
33064 KB |
Output is correct |
84 |
Correct |
161 ms |
33188 KB |
Output is correct |
85 |
Correct |
170 ms |
33064 KB |
Output is correct |
86 |
Correct |
178 ms |
32980 KB |
Output is correct |
87 |
Correct |
166 ms |
32952 KB |
Output is correct |
88 |
Correct |
269 ms |
33060 KB |
Output is correct |
89 |
Correct |
267 ms |
33064 KB |
Output is correct |
90 |
Correct |
130 ms |
32980 KB |
Output is correct |
91 |
Correct |
265 ms |
32980 KB |
Output is correct |
92 |
Correct |
249 ms |
32980 KB |
Output is correct |
93 |
Correct |
152 ms |
32980 KB |
Output is correct |