#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n,l;
cin>>n>>l;
vector<long long> tr(n+1);
vector<long long> tl(n+1);
vector<long long> rd(n+1);
vector<long long> ld(n+1);
rd[0] = 0;
ld[0] = 0;
tr[0] = 0;
tl[0] = 0;
for(int i = 1;i<n+1;i++)
{
cin>>rd[i];
ld[n-i+1] = l-rd[i];
}
for(int i = 1;i<n+1;i++)
{
cin>>tr[i];
tl[n-i+1] = tr[i];
}
long long m = 1000000000;
m *=m;
long long dp[n+1][n+1][n+1][2];
dp[0][0][0][0] = 0;
dp[0][0][0][1] = 0;
for(int i = 1;i<n+1;i++)
{
dp[0][0][i][0] = m;
dp[0][0][i][1] = m;
}
for(int i = 1;i<n+1;i++)
{
for(int q = 0;q<n+1;q++)
{
dp[i][0][q][0] = m;
dp[i][0][q][1] = m;
dp[i][0][q][0] = dp[i-1][0][q][0]-ld[i-1]+ld[i];
if(q!=0 && dp[i-1][0][q-1][0]+ld[i]-ld[i-1] <= tl[i])
{
dp[i][0][q][0] = min(dp[i][0][q][0],dp[i-1][0][q-1][0]+ld[i]-ld[i-1]);
}
dp[i][0][q][1] = 2*dp[i][0][q][0];
}
}
for(int j = 1;j<n+1;j++)
{
for(int q = 0;q<n+1;q++)
{
dp[0][j][q][1] = m;
dp[0][j][q][0] = m;
dp[0][j][q][1] = dp[0][j-1][q][1]-rd[j-1]+rd[j];
if(q!= 0 &&dp[0][j-1][q-1][1]+rd[j]-rd[j-1] <= tr[j])
{
dp[0][j][q][1] = min(dp[0][j][q][1],dp[0][j-1][q-1][1]+rd[j]-rd[j-1]);
}
dp[0][j][q][0] = 2*dp[0][j][q][1];
}
}
for(int i = 1;i<n+1;i++)
{
for(int j = 1;j<n+1;j++)
{
for(int q = 0;q<n+1;q++)
{
dp[i][j][q][0] = m;
dp[i][j][q][1] = m;
if(i+j > n) continue;
if(i!= 0)
{
dp[i][j][q][0] = min(dp[i-1][j][q][0]-ld[i-1]+ld[i],dp[i-1][j][q][1]+rd[j]+ld[i]);
}
if(q!=0 && dp[i-1][j][q-1][0]+ld[i]-ld[i-1] <= tl[i])
{
dp[i][j][q][0] = min(dp[i][j][q][0],dp[i-1][j][q-1][0]+ld[i]-ld[i-1]);
}
if(q!=0 && dp[i-1][j][q-1][1]+rd[j]+ld[i] <=tl[i])
{
dp[i][j][q][0] = min(dp[i][j][q][0],dp[i-1][j][q-1][1]+ld[i]+rd[j]);
}
if(j != 0)
{
dp[i][j][q][1] = min(dp[i][j-1][q][0]+ld[i]+rd[j],dp[i][j-1][q][1]-rd[j-1]+rd[j]);
}
if(q!= 0 && dp[i][j-1][q-1][0] + ld[i]+rd[j] <= tr[j])
{
dp[i][j][q][1] = min(dp[i][j][q][1],dp[i][j-1][q-1][0] + ld[i]+rd[j]);
}
if(q != 0 && dp[i][j-1][q-1][1] + rd[j]-rd[j-1] <= tr[j])
{
dp[i][j][q][1] = min(dp[i][j][q][1],dp[i][j-1][q-1][1]-rd[j-1]+rd[j]);
}
}
}
}
int ans = 0;
for(int i = 0;i<n+1;i++)
{
for(int j = 0;j<n+1;j++)
{
for(int q = 0;q<n+1;q++)
{
if(dp[i][j][q][0] < m) ans = max(ans,q);
if(dp[i][j][q][1] < m) ans = max(ans,q);
}
}
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
508 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
103 ms |
91728 KB |
Output is correct |
19 |
Correct |
46 ms |
43400 KB |
Output is correct |
20 |
Correct |
20 ms |
16976 KB |
Output is correct |
21 |
Correct |
44 ms |
39752 KB |
Output is correct |
22 |
Correct |
63 ms |
58696 KB |
Output is correct |
23 |
Correct |
14 ms |
13392 KB |
Output is correct |
24 |
Correct |
10 ms |
9400 KB |
Output is correct |
25 |
Correct |
14 ms |
12880 KB |
Output is correct |
26 |
Correct |
4 ms |
3152 KB |
Output is correct |
27 |
Correct |
16 ms |
13648 KB |
Output is correct |
28 |
Correct |
10 ms |
8272 KB |
Output is correct |
29 |
Correct |
16 ms |
14160 KB |
Output is correct |
30 |
Correct |
11 ms |
10064 KB |
Output is correct |
31 |
Correct |
14 ms |
13172 KB |
Output is correct |
32 |
Correct |
7 ms |
4944 KB |
Output is correct |
33 |
Correct |
15 ms |
12880 KB |
Output is correct |
34 |
Correct |
4 ms |
3068 KB |
Output is correct |
35 |
Correct |
13 ms |
12640 KB |
Output is correct |
36 |
Correct |
5 ms |
4176 KB |
Output is correct |
37 |
Correct |
14 ms |
13648 KB |
Output is correct |
38 |
Correct |
6 ms |
5712 KB |
Output is correct |
39 |
Correct |
16 ms |
14672 KB |
Output is correct |
40 |
Correct |
8 ms |
6736 KB |
Output is correct |
41 |
Correct |
144 ms |
125512 KB |
Output is correct |
42 |
Correct |
69 ms |
69448 KB |
Output is correct |
43 |
Correct |
127 ms |
125512 KB |
Output is correct |
44 |
Correct |
71 ms |
68168 KB |
Output is correct |
45 |
Correct |
128 ms |
125516 KB |
Output is correct |
46 |
Correct |
71 ms |
69448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
504 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
504 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
508 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
103 ms |
91728 KB |
Output is correct |
37 |
Correct |
46 ms |
43400 KB |
Output is correct |
38 |
Correct |
20 ms |
16976 KB |
Output is correct |
39 |
Correct |
44 ms |
39752 KB |
Output is correct |
40 |
Correct |
63 ms |
58696 KB |
Output is correct |
41 |
Correct |
14 ms |
13392 KB |
Output is correct |
42 |
Correct |
10 ms |
9400 KB |
Output is correct |
43 |
Correct |
14 ms |
12880 KB |
Output is correct |
44 |
Correct |
4 ms |
3152 KB |
Output is correct |
45 |
Correct |
16 ms |
13648 KB |
Output is correct |
46 |
Correct |
10 ms |
8272 KB |
Output is correct |
47 |
Correct |
16 ms |
14160 KB |
Output is correct |
48 |
Correct |
11 ms |
10064 KB |
Output is correct |
49 |
Correct |
14 ms |
13172 KB |
Output is correct |
50 |
Correct |
7 ms |
4944 KB |
Output is correct |
51 |
Correct |
15 ms |
12880 KB |
Output is correct |
52 |
Correct |
4 ms |
3068 KB |
Output is correct |
53 |
Correct |
13 ms |
12640 KB |
Output is correct |
54 |
Correct |
5 ms |
4176 KB |
Output is correct |
55 |
Correct |
14 ms |
13648 KB |
Output is correct |
56 |
Correct |
6 ms |
5712 KB |
Output is correct |
57 |
Correct |
16 ms |
14672 KB |
Output is correct |
58 |
Correct |
8 ms |
6736 KB |
Output is correct |
59 |
Correct |
144 ms |
125512 KB |
Output is correct |
60 |
Correct |
69 ms |
69448 KB |
Output is correct |
61 |
Correct |
127 ms |
125512 KB |
Output is correct |
62 |
Correct |
71 ms |
68168 KB |
Output is correct |
63 |
Correct |
128 ms |
125516 KB |
Output is correct |
64 |
Correct |
71 ms |
69448 KB |
Output is correct |
65 |
Correct |
112 ms |
107636 KB |
Output is correct |
66 |
Correct |
105 ms |
94792 KB |
Output is correct |
67 |
Correct |
91 ms |
88552 KB |
Output is correct |
68 |
Correct |
87 ms |
78664 KB |
Output is correct |
69 |
Correct |
111 ms |
105980 KB |
Output is correct |
70 |
Correct |
112 ms |
99400 KB |
Output is correct |
71 |
Correct |
101 ms |
101028 KB |
Output is correct |
72 |
Correct |
107 ms |
102728 KB |
Output is correct |
73 |
Correct |
101 ms |
91680 KB |
Output is correct |
74 |
Correct |
85 ms |
82760 KB |
Output is correct |
75 |
Correct |
100 ms |
96328 KB |
Output is correct |
76 |
Correct |
123 ms |
118344 KB |
Output is correct |
77 |
Correct |
135 ms |
118088 KB |
Output is correct |
78 |
Correct |
88 ms |
80080 KB |
Output is correct |
79 |
Correct |
88 ms |
84248 KB |
Output is correct |
80 |
Correct |
127 ms |
114504 KB |
Output is correct |
81 |
Correct |
92 ms |
85576 KB |
Output is correct |
82 |
Correct |
99 ms |
93192 KB |
Output is correct |
83 |
Correct |
142 ms |
125456 KB |
Output is correct |
84 |
Correct |
106 ms |
99464 KB |
Output is correct |
85 |
Correct |
123 ms |
112976 KB |
Output is correct |
86 |
Correct |
120 ms |
109380 KB |
Output is correct |
87 |
Correct |
101 ms |
96328 KB |
Output is correct |
88 |
Correct |
140 ms |
127560 KB |
Output is correct |
89 |
Correct |
132 ms |
127360 KB |
Output is correct |
90 |
Correct |
99 ms |
97864 KB |
Output is correct |
91 |
Correct |
136 ms |
127572 KB |
Output is correct |
92 |
Correct |
141 ms |
127448 KB |
Output is correct |
93 |
Correct |
132 ms |
123720 KB |
Output is correct |