# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=215;
long long n,x[N],dp[N][N][N][2],t[N],le,ri,l,ans,ff,ff1,dist;
long long go(long long x, long long xx) {
if (x<xx) swap(x,xx);
return min(x-xx,xx-x+l);
}
long long mn(long long a, long long b , long long c) {
return(min(a,min(b,c)));
}
int check(int le ,int ri) {
if (le==0) return 1;
if (le<ri) return 0;
return 1;
}
int main() {
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 le=0; le<=n+1; le++) {
for (int ri=0; ri<=n+1; ri++) {
for (int cnt=0; cnt<=n+1; cnt++) {
dp[le][ri][cnt][0]=dp[le][ri][cnt][1]=1e17;
}
}
}
dp[0][0][0][0]=0;
dp[0][0][0][1]=0;
x[0]=l;
for (int sz=1; sz<=n; sz++) {
for (int ri=0; ri<=sz; ri++) {
if (ri==sz) le=0;
else le=n-(sz-ri)+1;
ff=ff1=0;
if (le<ri && le!=0) continue;
for (int cnt=0; cnt<=sz; cnt++) {
if (le && check((le+1)%(n+1),ri))
{
dist=min(dp[(le+1)%(n+1)][ri][cnt][0]+go(x[(le+1)%(n+1)],x[le]),dp[(le+1)%(n+1)][ri][cnt][1]+go(x[ri], x[le]));
if (dist<=t[le]) dp[le][ri][cnt+1][0]=min(dp[le][ri][cnt+1][0],dist);
dp[le][ri][cnt][0]=mn(dp[le][ri][cnt][0],dp[(le+1)%(n+1)][ri][cnt][0]+go(x[(le+1)%(n+1)],x[le]),dp[(le+1)%(n+1)][ri][cnt][1]+go(x[ri], x[le]));
}
if (ri) {
dist=min(dp[le][ri-1][cnt][1]+go(x[ri-1], x[ri]),dp[le][ri-1][cnt][0]+go(x[le],x[ri]));
if (dist<=t[ri]) dp[le][ri][cnt+1][1]=min(dp[le][ri][cnt+1][1],dist);
dp[le][ri][cnt][1]=mn(dp[le][ri][cnt][1],dp[le][ri-1][cnt][1]+go(x[ri-1], x[ri]),dp[le][ri-1][cnt][0]+go(x[le],x[ri]));
}
if (dp[le][ri][cnt][0]<(long long)1e17 || dp[le][ri][cnt][1]<(long long)1e17) { ans=max(ans,(long long)cnt);}
}
// if (sz==2 && le==6 && ri==1) cout<<dp[6][1][2][1]<<endl;
/*for (int cnt=sz; cnt>=1; cnt--) {
if (dp[le][ri][cnt-1][1]<=t[ri] && !ff) {
ff=1;
dp[le][ri][cnt][1]=min(dp[le][ri][cnt][1],dp[le][ri][cnt-1][1]);
//if (sz==2 && le==6 && ri==1 && cnt==2)
// cout<<dp[le][ri][cnt][1]<<endl;
}
if (dp[le][ri][cnt-1][0]<=t[le] && !ff1) {
ff1=1;
dp[le][ri][cnt][0]=min(dp[le][ri][cnt][0],dp[le][ri][cnt-1][0]);
}
if (dp[le][ri][cnt][0]<(long long)1e17 || dp[le][ri][cnt][1]<(long long)1e17) { ans=max(ans,(long long)cnt);}
}*/
}
}
//cout<<dp[6][1][2][0]<<endl;
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
972 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 |
972 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 |
972 KB |
Output is correct |
13 |
Correct |
1 ms |
976 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
972 KB |
Output is correct |
17 |
Correct |
1 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
972 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 |
972 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 |
972 KB |
Output is correct |
13 |
Correct |
1 ms |
976 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
972 KB |
Output is correct |
17 |
Correct |
1 ms |
972 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
972 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
1 ms |
716 KB |
Output is correct |
23 |
Correct |
1 ms |
1228 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1100 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
716 KB |
Output is correct |
29 |
Correct |
1 ms |
1228 KB |
Output is correct |
30 |
Correct |
1 ms |
1228 KB |
Output is correct |
31 |
Correct |
1 ms |
1100 KB |
Output is correct |
32 |
Correct |
1 ms |
972 KB |
Output is correct |
33 |
Correct |
2 ms |
1228 KB |
Output is correct |
34 |
Correct |
1 ms |
1228 KB |
Output is correct |
35 |
Correct |
1 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
972 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 |
972 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 |
972 KB |
Output is correct |
13 |
Correct |
1 ms |
976 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
972 KB |
Output is correct |
17 |
Correct |
1 ms |
972 KB |
Output is correct |
18 |
Correct |
89 ms |
111212 KB |
Output is correct |
19 |
Correct |
51 ms |
67736 KB |
Output is correct |
20 |
Correct |
26 ms |
36316 KB |
Output is correct |
21 |
Correct |
47 ms |
63820 KB |
Output is correct |
22 |
Correct |
64 ms |
82720 KB |
Output is correct |
23 |
Correct |
21 ms |
30924 KB |
Output is correct |
24 |
Correct |
16 ms |
24268 KB |
Output is correct |
25 |
Correct |
21 ms |
30288 KB |
Output is correct |
26 |
Correct |
7 ms |
11724 KB |
Output is correct |
27 |
Correct |
22 ms |
31604 KB |
Output is correct |
28 |
Correct |
14 ms |
22532 KB |
Output is correct |
29 |
Correct |
22 ms |
32204 KB |
Output is correct |
30 |
Correct |
17 ms |
25420 KB |
Output is correct |
31 |
Correct |
20 ms |
30320 KB |
Output is correct |
32 |
Correct |
10 ms |
16048 KB |
Output is correct |
33 |
Correct |
21 ms |
30284 KB |
Output is correct |
34 |
Correct |
7 ms |
10956 KB |
Output is correct |
35 |
Correct |
20 ms |
29612 KB |
Output is correct |
36 |
Correct |
8 ms |
14156 KB |
Output is correct |
37 |
Correct |
21 ms |
31564 KB |
Output is correct |
38 |
Correct |
12 ms |
17356 KB |
Output is correct |
39 |
Correct |
22 ms |
32844 KB |
Output is correct |
40 |
Correct |
12 ms |
19436 KB |
Output is correct |
41 |
Correct |
112 ms |
137028 KB |
Output is correct |
42 |
Correct |
72 ms |
92400 KB |
Output is correct |
43 |
Correct |
117 ms |
136952 KB |
Output is correct |
44 |
Correct |
71 ms |
91396 KB |
Output is correct |
45 |
Correct |
117 ms |
137024 KB |
Output is correct |
46 |
Correct |
73 ms |
92420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
972 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 |
972 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 |
972 KB |
Output is correct |
13 |
Correct |
1 ms |
976 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
972 KB |
Output is correct |
17 |
Correct |
1 ms |
972 KB |
Output is correct |
18 |
Correct |
1 ms |
1100 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
972 KB |
Output is correct |
21 |
Correct |
1 ms |
1100 KB |
Output is correct |
22 |
Correct |
1 ms |
716 KB |
Output is correct |
23 |
Correct |
1 ms |
1228 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1100 KB |
Output is correct |
27 |
Correct |
1 ms |
588 KB |
Output is correct |
28 |
Correct |
1 ms |
716 KB |
Output is correct |
29 |
Correct |
1 ms |
1228 KB |
Output is correct |
30 |
Correct |
1 ms |
1228 KB |
Output is correct |
31 |
Correct |
1 ms |
1100 KB |
Output is correct |
32 |
Correct |
1 ms |
972 KB |
Output is correct |
33 |
Correct |
2 ms |
1228 KB |
Output is correct |
34 |
Correct |
1 ms |
1228 KB |
Output is correct |
35 |
Correct |
1 ms |
1228 KB |
Output is correct |
36 |
Correct |
89 ms |
111212 KB |
Output is correct |
37 |
Correct |
51 ms |
67736 KB |
Output is correct |
38 |
Correct |
26 ms |
36316 KB |
Output is correct |
39 |
Correct |
47 ms |
63820 KB |
Output is correct |
40 |
Correct |
64 ms |
82720 KB |
Output is correct |
41 |
Correct |
21 ms |
30924 KB |
Output is correct |
42 |
Correct |
16 ms |
24268 KB |
Output is correct |
43 |
Correct |
21 ms |
30288 KB |
Output is correct |
44 |
Correct |
7 ms |
11724 KB |
Output is correct |
45 |
Correct |
22 ms |
31604 KB |
Output is correct |
46 |
Correct |
14 ms |
22532 KB |
Output is correct |
47 |
Correct |
22 ms |
32204 KB |
Output is correct |
48 |
Correct |
17 ms |
25420 KB |
Output is correct |
49 |
Correct |
20 ms |
30320 KB |
Output is correct |
50 |
Correct |
10 ms |
16048 KB |
Output is correct |
51 |
Correct |
21 ms |
30284 KB |
Output is correct |
52 |
Correct |
7 ms |
10956 KB |
Output is correct |
53 |
Correct |
20 ms |
29612 KB |
Output is correct |
54 |
Correct |
8 ms |
14156 KB |
Output is correct |
55 |
Correct |
21 ms |
31564 KB |
Output is correct |
56 |
Correct |
12 ms |
17356 KB |
Output is correct |
57 |
Correct |
22 ms |
32844 KB |
Output is correct |
58 |
Correct |
12 ms |
19436 KB |
Output is correct |
59 |
Correct |
112 ms |
137028 KB |
Output is correct |
60 |
Correct |
72 ms |
92400 KB |
Output is correct |
61 |
Correct |
117 ms |
136952 KB |
Output is correct |
62 |
Correct |
71 ms |
91396 KB |
Output is correct |
63 |
Correct |
117 ms |
137024 KB |
Output is correct |
64 |
Correct |
73 ms |
92420 KB |
Output is correct |
65 |
Correct |
100 ms |
123804 KB |
Output is correct |
66 |
Correct |
92 ms |
113640 KB |
Output is correct |
67 |
Correct |
86 ms |
108708 KB |
Output is correct |
68 |
Correct |
80 ms |
100464 KB |
Output is correct |
69 |
Correct |
99 ms |
122436 KB |
Output is correct |
70 |
Correct |
99 ms |
117328 KB |
Output is correct |
71 |
Correct |
95 ms |
118664 KB |
Output is correct |
72 |
Correct |
103 ms |
119876 KB |
Output is correct |
73 |
Correct |
89 ms |
111108 KB |
Output is correct |
74 |
Correct |
88 ms |
103964 KB |
Output is correct |
75 |
Correct |
93 ms |
114880 KB |
Output is correct |
76 |
Correct |
112 ms |
131704 KB |
Output is correct |
77 |
Correct |
110 ms |
131556 KB |
Output is correct |
78 |
Correct |
83 ms |
101572 KB |
Output is correct |
79 |
Correct |
84 ms |
105188 KB |
Output is correct |
80 |
Correct |
110 ms |
128912 KB |
Output is correct |
81 |
Correct |
85 ms |
106388 KB |
Output is correct |
82 |
Correct |
91 ms |
112368 KB |
Output is correct |
83 |
Correct |
116 ms |
137028 KB |
Output is correct |
84 |
Correct |
94 ms |
117412 KB |
Output is correct |
85 |
Correct |
104 ms |
127660 KB |
Output is correct |
86 |
Correct |
103 ms |
125028 KB |
Output is correct |
87 |
Correct |
93 ms |
114888 KB |
Output is correct |
88 |
Correct |
116 ms |
138416 KB |
Output is correct |
89 |
Correct |
116 ms |
138324 KB |
Output is correct |
90 |
Correct |
97 ms |
116292 KB |
Output is correct |
91 |
Correct |
116 ms |
138440 KB |
Output is correct |
92 |
Correct |
115 ms |
138384 KB |
Output is correct |
93 |
Correct |
112 ms |
135620 KB |
Output is correct |