#include <bits/stdc++.h>
using namespace std ;
const int inf = 2e9 ;
const int MAX = 210 ;
long long X[MAX] , T[MAX] ;
int n ;
long long L ;
long long dp[MAX][MAX][MAX][2] ;
long long dist(int i , int j , int a , int b)
{
if(b == 0)
{
if(a == 0)
return (X[i] - X[i-1]) ;
else
return (L - X[j] + X[i-1]) ;
}
else
{
if(a == 1)
return (X[j+1] - X[j]) ;
else
return (X[i] + L - X[j+1]) ;
}
}
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
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 i = 0 ; i <= n+1 ; ++i)
{
for(int j = 0 ; j <= n+1 ; ++j)
{
for(int taken = 1 ; taken <= n+1 ; ++taken)
{
for(int a = 0 ; a <= 1 ; ++a)
dp[i][j][taken][a] = inf ;
}
}
}
X[n+1] = L ;
int ans = 0 ;
for(int i = 1 ; i <= n ; ++i)
{
for(int j = n ; j >= i ; --j)
{
for(int taken = 0 ; taken <= n ; ++taken)
{
for(int a = 0 ; a <= 1 ; ++a)
{
long long x , y ;
x = dp[i-1][j][taken][0] + dist(i , j , a , 0) ;
y = dp[i][j+1][taken][1] + dist(i , j , a , 1) ;
dp[i][j][taken][a] = min(x , y) ;
if(taken)
{
x = dp[i-1][j][taken-1][0] + dist(i , j , a , 0) ;
y = dp[i][j+1][taken-1][1] + dist(i , j , a , 1) ;
if((a == 0 && min(x , y) <= T[i]) || (a == 1 && min(x , y) <= T[j]))
{
dp[i][j][taken][a] = min(dp[i][j][taken][a] , min(x , y)) ;
ans = max(ans , taken) ;
}
}
}
}
}
}
return cout<<ans<<"\n" , 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
760 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
1016 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
888 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
1016 KB |
Output is correct |
17 |
Correct |
6 ms |
1016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
760 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
1016 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
888 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
1016 KB |
Output is correct |
17 |
Correct |
6 ms |
1016 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
5 ms |
888 KB |
Output is correct |
20 |
Correct |
5 ms |
1016 KB |
Output is correct |
21 |
Correct |
5 ms |
1144 KB |
Output is correct |
22 |
Correct |
5 ms |
760 KB |
Output is correct |
23 |
Correct |
5 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
1144 KB |
Output is correct |
25 |
Correct |
5 ms |
1148 KB |
Output is correct |
26 |
Correct |
5 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
760 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
1272 KB |
Output is correct |
30 |
Correct |
5 ms |
1400 KB |
Output is correct |
31 |
Correct |
5 ms |
1144 KB |
Output is correct |
32 |
Correct |
5 ms |
1144 KB |
Output is correct |
33 |
Correct |
5 ms |
1272 KB |
Output is correct |
34 |
Correct |
5 ms |
1272 KB |
Output is correct |
35 |
Correct |
5 ms |
1272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
760 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
1016 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
888 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
1016 KB |
Output is correct |
17 |
Correct |
6 ms |
1016 KB |
Output is correct |
18 |
Correct |
85 ms |
108664 KB |
Output is correct |
19 |
Correct |
50 ms |
66168 KB |
Output is correct |
20 |
Correct |
27 ms |
35576 KB |
Output is correct |
21 |
Correct |
47 ms |
62456 KB |
Output is correct |
22 |
Correct |
62 ms |
80892 KB |
Output is correct |
23 |
Correct |
24 ms |
30328 KB |
Output is correct |
24 |
Correct |
19 ms |
23800 KB |
Output is correct |
25 |
Correct |
24 ms |
29688 KB |
Output is correct |
26 |
Correct |
11 ms |
11512 KB |
Output is correct |
27 |
Correct |
24 ms |
30968 KB |
Output is correct |
28 |
Correct |
18 ms |
22136 KB |
Output is correct |
29 |
Correct |
25 ms |
31608 KB |
Output is correct |
30 |
Correct |
20 ms |
24824 KB |
Output is correct |
31 |
Correct |
22 ms |
29560 KB |
Output is correct |
32 |
Correct |
14 ms |
15736 KB |
Output is correct |
33 |
Correct |
23 ms |
29688 KB |
Output is correct |
34 |
Correct |
10 ms |
10744 KB |
Output is correct |
35 |
Correct |
22 ms |
29048 KB |
Output is correct |
36 |
Correct |
13 ms |
13944 KB |
Output is correct |
37 |
Correct |
24 ms |
30840 KB |
Output is correct |
38 |
Correct |
15 ms |
17144 KB |
Output is correct |
39 |
Correct |
25 ms |
32248 KB |
Output is correct |
40 |
Correct |
16 ms |
19064 KB |
Output is correct |
41 |
Correct |
111 ms |
133880 KB |
Output is correct |
42 |
Correct |
71 ms |
90576 KB |
Output is correct |
43 |
Correct |
110 ms |
134008 KB |
Output is correct |
44 |
Correct |
67 ms |
89336 KB |
Output is correct |
45 |
Correct |
109 ms |
133880 KB |
Output is correct |
46 |
Correct |
66 ms |
90360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
760 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
632 KB |
Output is correct |
6 |
Correct |
5 ms |
1016 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
888 KB |
Output is correct |
9 |
Correct |
5 ms |
1016 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
1016 KB |
Output is correct |
13 |
Correct |
5 ms |
1016 KB |
Output is correct |
14 |
Correct |
5 ms |
632 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
1016 KB |
Output is correct |
17 |
Correct |
6 ms |
1016 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
5 ms |
888 KB |
Output is correct |
20 |
Correct |
5 ms |
1016 KB |
Output is correct |
21 |
Correct |
5 ms |
1144 KB |
Output is correct |
22 |
Correct |
5 ms |
760 KB |
Output is correct |
23 |
Correct |
5 ms |
1272 KB |
Output is correct |
24 |
Correct |
5 ms |
1144 KB |
Output is correct |
25 |
Correct |
5 ms |
1148 KB |
Output is correct |
26 |
Correct |
5 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
760 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
5 ms |
1272 KB |
Output is correct |
30 |
Correct |
5 ms |
1400 KB |
Output is correct |
31 |
Correct |
5 ms |
1144 KB |
Output is correct |
32 |
Correct |
5 ms |
1144 KB |
Output is correct |
33 |
Correct |
5 ms |
1272 KB |
Output is correct |
34 |
Correct |
5 ms |
1272 KB |
Output is correct |
35 |
Correct |
5 ms |
1272 KB |
Output is correct |
36 |
Correct |
85 ms |
108664 KB |
Output is correct |
37 |
Correct |
50 ms |
66168 KB |
Output is correct |
38 |
Correct |
27 ms |
35576 KB |
Output is correct |
39 |
Correct |
47 ms |
62456 KB |
Output is correct |
40 |
Correct |
62 ms |
80892 KB |
Output is correct |
41 |
Correct |
24 ms |
30328 KB |
Output is correct |
42 |
Correct |
19 ms |
23800 KB |
Output is correct |
43 |
Correct |
24 ms |
29688 KB |
Output is correct |
44 |
Correct |
11 ms |
11512 KB |
Output is correct |
45 |
Correct |
24 ms |
30968 KB |
Output is correct |
46 |
Correct |
18 ms |
22136 KB |
Output is correct |
47 |
Correct |
25 ms |
31608 KB |
Output is correct |
48 |
Correct |
20 ms |
24824 KB |
Output is correct |
49 |
Correct |
22 ms |
29560 KB |
Output is correct |
50 |
Correct |
14 ms |
15736 KB |
Output is correct |
51 |
Correct |
23 ms |
29688 KB |
Output is correct |
52 |
Correct |
10 ms |
10744 KB |
Output is correct |
53 |
Correct |
22 ms |
29048 KB |
Output is correct |
54 |
Correct |
13 ms |
13944 KB |
Output is correct |
55 |
Correct |
24 ms |
30840 KB |
Output is correct |
56 |
Correct |
15 ms |
17144 KB |
Output is correct |
57 |
Correct |
25 ms |
32248 KB |
Output is correct |
58 |
Correct |
16 ms |
19064 KB |
Output is correct |
59 |
Correct |
111 ms |
133880 KB |
Output is correct |
60 |
Correct |
71 ms |
90576 KB |
Output is correct |
61 |
Correct |
110 ms |
134008 KB |
Output is correct |
62 |
Correct |
67 ms |
89336 KB |
Output is correct |
63 |
Correct |
109 ms |
133880 KB |
Output is correct |
64 |
Correct |
66 ms |
90360 KB |
Output is correct |
65 |
Correct |
102 ms |
121208 KB |
Output is correct |
66 |
Correct |
87 ms |
111116 KB |
Output is correct |
67 |
Correct |
86 ms |
106360 KB |
Output is correct |
68 |
Correct |
77 ms |
98168 KB |
Output is correct |
69 |
Correct |
96 ms |
119672 KB |
Output is correct |
70 |
Correct |
95 ms |
114936 KB |
Output is correct |
71 |
Correct |
89 ms |
116088 KB |
Output is correct |
72 |
Correct |
93 ms |
117244 KB |
Output is correct |
73 |
Correct |
84 ms |
108664 KB |
Output is correct |
74 |
Correct |
83 ms |
101624 KB |
Output is correct |
75 |
Correct |
93 ms |
112376 KB |
Output is correct |
76 |
Correct |
103 ms |
128632 KB |
Output is correct |
77 |
Correct |
101 ms |
128632 KB |
Output is correct |
78 |
Correct |
77 ms |
99448 KB |
Output is correct |
79 |
Correct |
81 ms |
102776 KB |
Output is correct |
80 |
Correct |
102 ms |
126160 KB |
Output is correct |
81 |
Correct |
79 ms |
103928 KB |
Output is correct |
82 |
Correct |
85 ms |
109944 KB |
Output is correct |
83 |
Correct |
107 ms |
133880 KB |
Output is correct |
84 |
Correct |
90 ms |
114808 KB |
Output is correct |
85 |
Correct |
101 ms |
124920 KB |
Output is correct |
86 |
Correct |
95 ms |
122228 KB |
Output is correct |
87 |
Correct |
92 ms |
112376 KB |
Output is correct |
88 |
Correct |
113 ms |
135288 KB |
Output is correct |
89 |
Correct |
114 ms |
135288 KB |
Output is correct |
90 |
Correct |
89 ms |
113656 KB |
Output is correct |
91 |
Correct |
112 ms |
135288 KB |
Output is correct |
92 |
Correct |
115 ms |
135288 KB |
Output is correct |
93 |
Correct |
104 ms |
132676 KB |
Output is correct |