#include <bits/stdc++.h>
using namespace std;
#define cin(vec) for(auto& i : vec) cin >> i
#define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define loop(i,a,b) for (int i = a; i < b; i++)
#define F first
#define S second
#define pb(n) push_back(n)
#define pf(n) push_front(n)
#define dci(d) fixed<<setprecision(d)
#define sp ' '
#define el '\n'
#define all(v) v.begin(),v.end()
#define int long long
int dx[8]= {0,0,1,-1,-1,1,1,-1};
int dy[8]= {-1,1,0,0,-1,1,-1,1};
int const N=1e4+5,M=1e3+1,Mod=1e9+7;
int a[202],t[202],n,len;
int dp[202][202][202][2];
int dist(int t1,int t2,int i,int j){
if(t2==0){
if(t1==0)
return (a[i]-a[i-1]);
else
return (len-a[j]+a[i-1]);
}
else{
if(t1==1)
return (a[j+1]-a[j]);
else
return (a[i]+len-a[j+1]);
}
}
void testcase(int h){
cin>>n>>len;
int mx=0;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>t[i];
for(int i=0;i<=n+1;i++){
for(int j=n+1;j>=i;j--){
for(int t=0;t<=1;t++){
for(int cnt=1;cnt<=n+1;cnt++){
dp[i][j][cnt][t]=1e18;
}
}
}
}
a[n+1]=len;
for(int i=1;i<=n;i++){
for(int j=n;j>=i;j--){
for(int cnt=0;cnt<=n;cnt++){
for(int tp=0;tp<=1;tp++){
dp[i][j][cnt][tp]=min(dp[i-1][j][cnt][0]+dist(tp,0,i,j)
,dp[i][j+1][cnt][1]+dist(tp,1,i,j));
if(cnt){
int a=min(dp[i][j+1][cnt-1][1]+dist(tp,1,i,j)
,dp[i-1][j][cnt-1][0]+dist(tp,0,i,j));
if((!tp&&a<=t[i])||(tp&&a<=t[j])){
dp[i][j][cnt][tp]=min(dp[i][j][cnt][tp],a);
mx=max(mx,cnt);
}
}
}
}
}
}
cout<<mx;
}
int32_t main()
{
// fast
testcase(1);
// int tc;cin>>tc;for(int i=1;i<=tc;i++)testcase(i);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
572 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
724 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
724 KB |
Output is correct |
33 |
Correct |
1 ms |
724 KB |
Output is correct |
34 |
Correct |
1 ms |
724 KB |
Output is correct |
35 |
Correct |
1 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
42 ms |
53176 KB |
Output is correct |
19 |
Correct |
23 ms |
32460 KB |
Output is correct |
20 |
Correct |
12 ms |
17572 KB |
Output is correct |
21 |
Correct |
22 ms |
30676 KB |
Output is correct |
22 |
Correct |
29 ms |
39648 KB |
Output is correct |
23 |
Correct |
9 ms |
14932 KB |
Output is correct |
24 |
Correct |
7 ms |
11776 KB |
Output is correct |
25 |
Correct |
9 ms |
14732 KB |
Output is correct |
26 |
Correct |
3 ms |
5872 KB |
Output is correct |
27 |
Correct |
11 ms |
15344 KB |
Output is correct |
28 |
Correct |
7 ms |
10964 KB |
Output is correct |
29 |
Correct |
13 ms |
15564 KB |
Output is correct |
30 |
Correct |
8 ms |
12372 KB |
Output is correct |
31 |
Correct |
10 ms |
14664 KB |
Output is correct |
32 |
Correct |
4 ms |
7892 KB |
Output is correct |
33 |
Correct |
10 ms |
14676 KB |
Output is correct |
34 |
Correct |
3 ms |
5460 KB |
Output is correct |
35 |
Correct |
10 ms |
14316 KB |
Output is correct |
36 |
Correct |
4 ms |
6996 KB |
Output is correct |
37 |
Correct |
11 ms |
15316 KB |
Output is correct |
38 |
Correct |
6 ms |
8532 KB |
Output is correct |
39 |
Correct |
10 ms |
15964 KB |
Output is correct |
40 |
Correct |
6 ms |
9428 KB |
Output is correct |
41 |
Correct |
55 ms |
65408 KB |
Output is correct |
42 |
Correct |
38 ms |
44244 KB |
Output is correct |
43 |
Correct |
63 ms |
65404 KB |
Output is correct |
44 |
Correct |
31 ms |
43732 KB |
Output is correct |
45 |
Correct |
57 ms |
65424 KB |
Output is correct |
46 |
Correct |
34 ms |
44244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
572 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
724 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
724 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
724 KB |
Output is correct |
33 |
Correct |
1 ms |
724 KB |
Output is correct |
34 |
Correct |
1 ms |
724 KB |
Output is correct |
35 |
Correct |
1 ms |
724 KB |
Output is correct |
36 |
Correct |
42 ms |
53176 KB |
Output is correct |
37 |
Correct |
23 ms |
32460 KB |
Output is correct |
38 |
Correct |
12 ms |
17572 KB |
Output is correct |
39 |
Correct |
22 ms |
30676 KB |
Output is correct |
40 |
Correct |
29 ms |
39648 KB |
Output is correct |
41 |
Correct |
9 ms |
14932 KB |
Output is correct |
42 |
Correct |
7 ms |
11776 KB |
Output is correct |
43 |
Correct |
9 ms |
14732 KB |
Output is correct |
44 |
Correct |
3 ms |
5872 KB |
Output is correct |
45 |
Correct |
11 ms |
15344 KB |
Output is correct |
46 |
Correct |
7 ms |
10964 KB |
Output is correct |
47 |
Correct |
13 ms |
15564 KB |
Output is correct |
48 |
Correct |
8 ms |
12372 KB |
Output is correct |
49 |
Correct |
10 ms |
14664 KB |
Output is correct |
50 |
Correct |
4 ms |
7892 KB |
Output is correct |
51 |
Correct |
10 ms |
14676 KB |
Output is correct |
52 |
Correct |
3 ms |
5460 KB |
Output is correct |
53 |
Correct |
10 ms |
14316 KB |
Output is correct |
54 |
Correct |
4 ms |
6996 KB |
Output is correct |
55 |
Correct |
11 ms |
15316 KB |
Output is correct |
56 |
Correct |
6 ms |
8532 KB |
Output is correct |
57 |
Correct |
10 ms |
15964 KB |
Output is correct |
58 |
Correct |
6 ms |
9428 KB |
Output is correct |
59 |
Correct |
55 ms |
65408 KB |
Output is correct |
60 |
Correct |
38 ms |
44244 KB |
Output is correct |
61 |
Correct |
63 ms |
65404 KB |
Output is correct |
62 |
Correct |
31 ms |
43732 KB |
Output is correct |
63 |
Correct |
57 ms |
65424 KB |
Output is correct |
64 |
Correct |
34 ms |
44244 KB |
Output is correct |
65 |
Correct |
54 ms |
59212 KB |
Output is correct |
66 |
Correct |
45 ms |
54324 KB |
Output is correct |
67 |
Correct |
41 ms |
51948 KB |
Output is correct |
68 |
Correct |
37 ms |
48064 KB |
Output is correct |
69 |
Correct |
47 ms |
58580 KB |
Output is correct |
70 |
Correct |
50 ms |
56096 KB |
Output is correct |
71 |
Correct |
45 ms |
56660 KB |
Output is correct |
72 |
Correct |
49 ms |
57300 KB |
Output is correct |
73 |
Correct |
39 ms |
53076 KB |
Output is correct |
74 |
Correct |
40 ms |
49732 KB |
Output is correct |
75 |
Correct |
41 ms |
54924 KB |
Output is correct |
76 |
Correct |
52 ms |
62856 KB |
Output is correct |
77 |
Correct |
50 ms |
62804 KB |
Output is correct |
78 |
Correct |
39 ms |
48588 KB |
Output is correct |
79 |
Correct |
41 ms |
50300 KB |
Output is correct |
80 |
Correct |
49 ms |
61512 KB |
Output is correct |
81 |
Correct |
39 ms |
50900 KB |
Output is correct |
82 |
Correct |
40 ms |
53716 KB |
Output is correct |
83 |
Correct |
51 ms |
65392 KB |
Output is correct |
84 |
Correct |
46 ms |
56040 KB |
Output is correct |
85 |
Correct |
47 ms |
60972 KB |
Output is correct |
86 |
Correct |
52 ms |
59644 KB |
Output is correct |
87 |
Correct |
41 ms |
54848 KB |
Output is correct |
88 |
Correct |
52 ms |
66040 KB |
Output is correct |
89 |
Correct |
54 ms |
66056 KB |
Output is correct |
90 |
Correct |
40 ms |
55508 KB |
Output is correct |
91 |
Correct |
57 ms |
66080 KB |
Output is correct |
92 |
Correct |
54 ms |
65956 KB |
Output is correct |
93 |
Correct |
49 ms |
64720 KB |
Output is correct |