#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[201][201][201][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 |
1 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
568 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
560 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
568 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
560 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
560 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
692 KB |
Output is correct |
22 |
Correct |
1 ms |
432 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 |
816 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
692 KB |
Output is correct |
32 |
Correct |
1 ms |
596 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 |
1 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
568 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
560 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
560 KB |
Output is correct |
18 |
Correct |
43 ms |
52908 KB |
Output is correct |
19 |
Correct |
22 ms |
32352 KB |
Output is correct |
20 |
Correct |
12 ms |
17492 KB |
Output is correct |
21 |
Correct |
25 ms |
30520 KB |
Output is correct |
22 |
Correct |
29 ms |
39380 KB |
Output is correct |
23 |
Correct |
11 ms |
14956 KB |
Output is correct |
24 |
Correct |
10 ms |
11732 KB |
Output is correct |
25 |
Correct |
10 ms |
14548 KB |
Output is correct |
26 |
Correct |
3 ms |
5844 KB |
Output is correct |
27 |
Correct |
10 ms |
15188 KB |
Output is correct |
28 |
Correct |
7 ms |
11092 KB |
Output is correct |
29 |
Correct |
10 ms |
15572 KB |
Output is correct |
30 |
Correct |
7 ms |
12244 KB |
Output is correct |
31 |
Correct |
10 ms |
14548 KB |
Output is correct |
32 |
Correct |
6 ms |
7860 KB |
Output is correct |
33 |
Correct |
9 ms |
14548 KB |
Output is correct |
34 |
Correct |
3 ms |
5460 KB |
Output is correct |
35 |
Correct |
9 ms |
14352 KB |
Output is correct |
36 |
Correct |
6 ms |
6968 KB |
Output is correct |
37 |
Correct |
10 ms |
15188 KB |
Output is correct |
38 |
Correct |
5 ms |
8532 KB |
Output is correct |
39 |
Correct |
11 ms |
15792 KB |
Output is correct |
40 |
Correct |
6 ms |
9428 KB |
Output is correct |
41 |
Correct |
55 ms |
65016 KB |
Output is correct |
42 |
Correct |
31 ms |
43968 KB |
Output is correct |
43 |
Correct |
51 ms |
65072 KB |
Output is correct |
44 |
Correct |
31 ms |
43552 KB |
Output is correct |
45 |
Correct |
54 ms |
65076 KB |
Output is correct |
46 |
Correct |
31 ms |
43988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
568 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
560 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
560 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
692 KB |
Output is correct |
22 |
Correct |
1 ms |
432 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 |
816 KB |
Output is correct |
30 |
Correct |
1 ms |
724 KB |
Output is correct |
31 |
Correct |
1 ms |
692 KB |
Output is correct |
32 |
Correct |
1 ms |
596 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 |
43 ms |
52908 KB |
Output is correct |
37 |
Correct |
22 ms |
32352 KB |
Output is correct |
38 |
Correct |
12 ms |
17492 KB |
Output is correct |
39 |
Correct |
25 ms |
30520 KB |
Output is correct |
40 |
Correct |
29 ms |
39380 KB |
Output is correct |
41 |
Correct |
11 ms |
14956 KB |
Output is correct |
42 |
Correct |
10 ms |
11732 KB |
Output is correct |
43 |
Correct |
10 ms |
14548 KB |
Output is correct |
44 |
Correct |
3 ms |
5844 KB |
Output is correct |
45 |
Correct |
10 ms |
15188 KB |
Output is correct |
46 |
Correct |
7 ms |
11092 KB |
Output is correct |
47 |
Correct |
10 ms |
15572 KB |
Output is correct |
48 |
Correct |
7 ms |
12244 KB |
Output is correct |
49 |
Correct |
10 ms |
14548 KB |
Output is correct |
50 |
Correct |
6 ms |
7860 KB |
Output is correct |
51 |
Correct |
9 ms |
14548 KB |
Output is correct |
52 |
Correct |
3 ms |
5460 KB |
Output is correct |
53 |
Correct |
9 ms |
14352 KB |
Output is correct |
54 |
Correct |
6 ms |
6968 KB |
Output is correct |
55 |
Correct |
10 ms |
15188 KB |
Output is correct |
56 |
Correct |
5 ms |
8532 KB |
Output is correct |
57 |
Correct |
11 ms |
15792 KB |
Output is correct |
58 |
Correct |
6 ms |
9428 KB |
Output is correct |
59 |
Correct |
55 ms |
65016 KB |
Output is correct |
60 |
Correct |
31 ms |
43968 KB |
Output is correct |
61 |
Correct |
51 ms |
65072 KB |
Output is correct |
62 |
Correct |
31 ms |
43552 KB |
Output is correct |
63 |
Correct |
54 ms |
65076 KB |
Output is correct |
64 |
Correct |
31 ms |
43988 KB |
Output is correct |
65 |
Correct |
52 ms |
58828 KB |
Output is correct |
66 |
Correct |
45 ms |
54056 KB |
Output is correct |
67 |
Correct |
41 ms |
51760 KB |
Output is correct |
68 |
Correct |
40 ms |
47828 KB |
Output is correct |
69 |
Correct |
49 ms |
58140 KB |
Output is correct |
70 |
Correct |
45 ms |
55828 KB |
Output is correct |
71 |
Correct |
45 ms |
56296 KB |
Output is correct |
72 |
Correct |
52 ms |
56972 KB |
Output is correct |
73 |
Correct |
49 ms |
52892 KB |
Output is correct |
74 |
Correct |
45 ms |
49484 KB |
Output is correct |
75 |
Correct |
41 ms |
54600 KB |
Output is correct |
76 |
Correct |
51 ms |
62684 KB |
Output is correct |
77 |
Correct |
48 ms |
62552 KB |
Output is correct |
78 |
Correct |
37 ms |
48340 KB |
Output is correct |
79 |
Correct |
40 ms |
50004 KB |
Output is correct |
80 |
Correct |
52 ms |
61184 KB |
Output is correct |
81 |
Correct |
44 ms |
50508 KB |
Output is correct |
82 |
Correct |
42 ms |
53420 KB |
Output is correct |
83 |
Correct |
51 ms |
65068 KB |
Output is correct |
84 |
Correct |
41 ms |
55828 KB |
Output is correct |
85 |
Correct |
47 ms |
60572 KB |
Output is correct |
86 |
Correct |
46 ms |
59444 KB |
Output is correct |
87 |
Correct |
56 ms |
54640 KB |
Output is correct |
88 |
Runtime error |
105 ms |
132956 KB |
Execution killed with signal 11 |
89 |
Halted |
0 ms |
0 KB |
- |