#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define int long long
#define sz(a) (int)a.size()
const int mxN = (int)4e2+10;
const int LINF = (int)2e18;
int dp[2][mxN][mxN][2], x[mxN], t[mxN];
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, L; cin >> n >> L; int ans = 0;
for(int i = 1; i <= n; i++) cin >> x[i], x[n+i+1]=x[i];
for(int i = 1; i <= n; i++) cin >> t[i], t[n+i+1]=t[i];
for(int i = 0; i < 2; i++)
for(int j = 0; j < mxN; j++)
for(int k = 0; k < mxN; k++)
for(int l = 0; l < 2; l++)
dp[i][j][k][l] = LINF;
dp[0][n+1][n+1][0]=dp[0][n+1][n+1][1]=0; t[n+1] = -LINF;
for(int kk = 0, k=0, lk=1; kk <= n; kk++,k^=1,lk^=1){
for(int len = 2; len <= n+1; len++){
for(int l = 1, r=l+len-1; l <= n+1; l++, r++){
dp[k][l][r][0] = min({ dp[k][l][r][0],
dp[k][l+1][r][0]+min(abs(x[l+1]-x[l]),L-abs(x[l+1]-x[l])),
dp[k][l+1][r][1]+min(abs(x[r]-x[l]),L-abs(x[r]-x[l]))
});
dp[k][l][r][1] = min({ dp[k][l][r][1],
dp[k][l][r-1][0]+min(abs(x[l]-x[r]),L-abs(x[l]-x[r])),
dp[k][l][r-1][1]+min(abs(x[r-1]-x[r]),L-abs(x[r-1]-x[r]))
});
if(kk){
int tm = abs(x[l+1]-x[l]); tm=min(tm,L-tm); tm+=dp[lk][l+1][r][0];
if(tm<=t[l]) dp[k][l][r][0] = min(dp[k][l][r][0], tm);
tm = abs(x[r]-x[l]); tm=min(tm,L-tm); tm+=dp[lk][l+1][r][1];
if(tm<=t[l]) dp[k][l][r][0] = min(dp[k][l][r][0], tm);
tm = abs(x[l]-x[r]); tm=min(tm,L-tm); tm+=dp[lk][l][r-1][0];
if(tm<=t[r]) dp[k][l][r][1] = min(dp[k][l][r][1],tm);
tm = abs(x[r-1]-x[r]); tm=min(tm,L-tm); tm+=dp[lk][l][r-1][1];
if(tm<=t[r]) dp[k][l][r][1] = min(dp[k][l][r][1],tm);
}
if(len==n+1 and (dp[k][l][r][0]<LINF or dp[k][l][r][1]<LINF)) ans = max(ans, kk);
}
}
for(int i = 0; i < mxN; i++)
for(int j = 0; j < mxN; j++)
for(int l = 0; l < 2; l++)
dp[lk][i][j][l]=LINF;
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5460 KB |
Output is correct |
2 |
Correct |
3 ms |
5588 KB |
Output is correct |
3 |
Correct |
4 ms |
5460 KB |
Output is correct |
4 |
Correct |
4 ms |
5588 KB |
Output is correct |
5 |
Correct |
5 ms |
5588 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
3 ms |
5588 KB |
Output is correct |
8 |
Correct |
5 ms |
5588 KB |
Output is correct |
9 |
Correct |
5 ms |
5460 KB |
Output is correct |
10 |
Correct |
3 ms |
5588 KB |
Output is correct |
11 |
Correct |
3 ms |
5460 KB |
Output is correct |
12 |
Correct |
4 ms |
5460 KB |
Output is correct |
13 |
Correct |
4 ms |
5460 KB |
Output is correct |
14 |
Correct |
4 ms |
5588 KB |
Output is correct |
15 |
Correct |
4 ms |
5588 KB |
Output is correct |
16 |
Correct |
5 ms |
5460 KB |
Output is correct |
17 |
Correct |
4 ms |
5548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5460 KB |
Output is correct |
2 |
Correct |
3 ms |
5588 KB |
Output is correct |
3 |
Correct |
4 ms |
5460 KB |
Output is correct |
4 |
Correct |
4 ms |
5588 KB |
Output is correct |
5 |
Correct |
5 ms |
5588 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
3 ms |
5588 KB |
Output is correct |
8 |
Correct |
5 ms |
5588 KB |
Output is correct |
9 |
Correct |
5 ms |
5460 KB |
Output is correct |
10 |
Correct |
3 ms |
5588 KB |
Output is correct |
11 |
Correct |
3 ms |
5460 KB |
Output is correct |
12 |
Correct |
4 ms |
5460 KB |
Output is correct |
13 |
Correct |
4 ms |
5460 KB |
Output is correct |
14 |
Correct |
4 ms |
5588 KB |
Output is correct |
15 |
Correct |
4 ms |
5588 KB |
Output is correct |
16 |
Correct |
5 ms |
5460 KB |
Output is correct |
17 |
Correct |
4 ms |
5548 KB |
Output is correct |
18 |
Correct |
5 ms |
5460 KB |
Output is correct |
19 |
Correct |
4 ms |
5460 KB |
Output is correct |
20 |
Correct |
4 ms |
5588 KB |
Output is correct |
21 |
Correct |
5 ms |
5460 KB |
Output is correct |
22 |
Correct |
4 ms |
5460 KB |
Output is correct |
23 |
Correct |
6 ms |
5588 KB |
Output is correct |
24 |
Correct |
4 ms |
5460 KB |
Output is correct |
25 |
Correct |
5 ms |
5588 KB |
Output is correct |
26 |
Correct |
6 ms |
5460 KB |
Output is correct |
27 |
Correct |
4 ms |
5460 KB |
Output is correct |
28 |
Correct |
4 ms |
5540 KB |
Output is correct |
29 |
Correct |
4 ms |
5588 KB |
Output is correct |
30 |
Correct |
4 ms |
5588 KB |
Output is correct |
31 |
Correct |
5 ms |
5588 KB |
Output is correct |
32 |
Correct |
4 ms |
5588 KB |
Output is correct |
33 |
Correct |
5 ms |
5588 KB |
Output is correct |
34 |
Correct |
5 ms |
5588 KB |
Output is correct |
35 |
Correct |
5 ms |
5536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5460 KB |
Output is correct |
2 |
Correct |
3 ms |
5588 KB |
Output is correct |
3 |
Correct |
4 ms |
5460 KB |
Output is correct |
4 |
Correct |
4 ms |
5588 KB |
Output is correct |
5 |
Correct |
5 ms |
5588 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
3 ms |
5588 KB |
Output is correct |
8 |
Correct |
5 ms |
5588 KB |
Output is correct |
9 |
Correct |
5 ms |
5460 KB |
Output is correct |
10 |
Correct |
3 ms |
5588 KB |
Output is correct |
11 |
Correct |
3 ms |
5460 KB |
Output is correct |
12 |
Correct |
4 ms |
5460 KB |
Output is correct |
13 |
Correct |
4 ms |
5460 KB |
Output is correct |
14 |
Correct |
4 ms |
5588 KB |
Output is correct |
15 |
Correct |
4 ms |
5588 KB |
Output is correct |
16 |
Correct |
5 ms |
5460 KB |
Output is correct |
17 |
Correct |
4 ms |
5548 KB |
Output is correct |
18 |
Correct |
98 ms |
5576 KB |
Output is correct |
19 |
Correct |
50 ms |
5576 KB |
Output is correct |
20 |
Correct |
31 ms |
5588 KB |
Output is correct |
21 |
Correct |
42 ms |
5588 KB |
Output is correct |
22 |
Correct |
60 ms |
5568 KB |
Output is correct |
23 |
Correct |
21 ms |
5588 KB |
Output is correct |
24 |
Correct |
18 ms |
5576 KB |
Output is correct |
25 |
Correct |
21 ms |
5588 KB |
Output is correct |
26 |
Correct |
11 ms |
5588 KB |
Output is correct |
27 |
Correct |
25 ms |
5592 KB |
Output is correct |
28 |
Correct |
17 ms |
5588 KB |
Output is correct |
29 |
Correct |
23 ms |
5588 KB |
Output is correct |
30 |
Correct |
20 ms |
5588 KB |
Output is correct |
31 |
Correct |
21 ms |
5460 KB |
Output is correct |
32 |
Correct |
14 ms |
5588 KB |
Output is correct |
33 |
Correct |
22 ms |
5596 KB |
Output is correct |
34 |
Correct |
11 ms |
5576 KB |
Output is correct |
35 |
Correct |
20 ms |
5588 KB |
Output is correct |
36 |
Correct |
13 ms |
5596 KB |
Output is correct |
37 |
Correct |
21 ms |
5588 KB |
Output is correct |
38 |
Correct |
14 ms |
5592 KB |
Output is correct |
39 |
Correct |
23 ms |
5592 KB |
Output is correct |
40 |
Correct |
16 ms |
5588 KB |
Output is correct |
41 |
Correct |
102 ms |
5568 KB |
Output is correct |
42 |
Correct |
57 ms |
5588 KB |
Output is correct |
43 |
Correct |
95 ms |
5588 KB |
Output is correct |
44 |
Correct |
62 ms |
5588 KB |
Output is correct |
45 |
Correct |
96 ms |
5588 KB |
Output is correct |
46 |
Correct |
68 ms |
5576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5460 KB |
Output is correct |
2 |
Correct |
3 ms |
5588 KB |
Output is correct |
3 |
Correct |
4 ms |
5460 KB |
Output is correct |
4 |
Correct |
4 ms |
5588 KB |
Output is correct |
5 |
Correct |
5 ms |
5588 KB |
Output is correct |
6 |
Correct |
4 ms |
5460 KB |
Output is correct |
7 |
Correct |
3 ms |
5588 KB |
Output is correct |
8 |
Correct |
5 ms |
5588 KB |
Output is correct |
9 |
Correct |
5 ms |
5460 KB |
Output is correct |
10 |
Correct |
3 ms |
5588 KB |
Output is correct |
11 |
Correct |
3 ms |
5460 KB |
Output is correct |
12 |
Correct |
4 ms |
5460 KB |
Output is correct |
13 |
Correct |
4 ms |
5460 KB |
Output is correct |
14 |
Correct |
4 ms |
5588 KB |
Output is correct |
15 |
Correct |
4 ms |
5588 KB |
Output is correct |
16 |
Correct |
5 ms |
5460 KB |
Output is correct |
17 |
Correct |
4 ms |
5548 KB |
Output is correct |
18 |
Correct |
5 ms |
5460 KB |
Output is correct |
19 |
Correct |
4 ms |
5460 KB |
Output is correct |
20 |
Correct |
4 ms |
5588 KB |
Output is correct |
21 |
Correct |
5 ms |
5460 KB |
Output is correct |
22 |
Correct |
4 ms |
5460 KB |
Output is correct |
23 |
Correct |
6 ms |
5588 KB |
Output is correct |
24 |
Correct |
4 ms |
5460 KB |
Output is correct |
25 |
Correct |
5 ms |
5588 KB |
Output is correct |
26 |
Correct |
6 ms |
5460 KB |
Output is correct |
27 |
Correct |
4 ms |
5460 KB |
Output is correct |
28 |
Correct |
4 ms |
5540 KB |
Output is correct |
29 |
Correct |
4 ms |
5588 KB |
Output is correct |
30 |
Correct |
4 ms |
5588 KB |
Output is correct |
31 |
Correct |
5 ms |
5588 KB |
Output is correct |
32 |
Correct |
4 ms |
5588 KB |
Output is correct |
33 |
Correct |
5 ms |
5588 KB |
Output is correct |
34 |
Correct |
5 ms |
5588 KB |
Output is correct |
35 |
Correct |
5 ms |
5536 KB |
Output is correct |
36 |
Correct |
98 ms |
5576 KB |
Output is correct |
37 |
Correct |
50 ms |
5576 KB |
Output is correct |
38 |
Correct |
31 ms |
5588 KB |
Output is correct |
39 |
Correct |
42 ms |
5588 KB |
Output is correct |
40 |
Correct |
60 ms |
5568 KB |
Output is correct |
41 |
Correct |
21 ms |
5588 KB |
Output is correct |
42 |
Correct |
18 ms |
5576 KB |
Output is correct |
43 |
Correct |
21 ms |
5588 KB |
Output is correct |
44 |
Correct |
11 ms |
5588 KB |
Output is correct |
45 |
Correct |
25 ms |
5592 KB |
Output is correct |
46 |
Correct |
17 ms |
5588 KB |
Output is correct |
47 |
Correct |
23 ms |
5588 KB |
Output is correct |
48 |
Correct |
20 ms |
5588 KB |
Output is correct |
49 |
Correct |
21 ms |
5460 KB |
Output is correct |
50 |
Correct |
14 ms |
5588 KB |
Output is correct |
51 |
Correct |
22 ms |
5596 KB |
Output is correct |
52 |
Correct |
11 ms |
5576 KB |
Output is correct |
53 |
Correct |
20 ms |
5588 KB |
Output is correct |
54 |
Correct |
13 ms |
5596 KB |
Output is correct |
55 |
Correct |
21 ms |
5588 KB |
Output is correct |
56 |
Correct |
14 ms |
5592 KB |
Output is correct |
57 |
Correct |
23 ms |
5592 KB |
Output is correct |
58 |
Correct |
16 ms |
5588 KB |
Output is correct |
59 |
Correct |
102 ms |
5568 KB |
Output is correct |
60 |
Correct |
57 ms |
5588 KB |
Output is correct |
61 |
Correct |
95 ms |
5588 KB |
Output is correct |
62 |
Correct |
62 ms |
5588 KB |
Output is correct |
63 |
Correct |
96 ms |
5588 KB |
Output is correct |
64 |
Correct |
68 ms |
5576 KB |
Output is correct |
65 |
Correct |
93 ms |
5588 KB |
Output is correct |
66 |
Correct |
77 ms |
5588 KB |
Output is correct |
67 |
Correct |
83 ms |
5588 KB |
Output is correct |
68 |
Correct |
71 ms |
5576 KB |
Output is correct |
69 |
Correct |
86 ms |
5572 KB |
Output is correct |
70 |
Correct |
82 ms |
5588 KB |
Output is correct |
71 |
Correct |
78 ms |
5576 KB |
Output is correct |
72 |
Correct |
83 ms |
5588 KB |
Output is correct |
73 |
Correct |
71 ms |
5588 KB |
Output is correct |
74 |
Correct |
89 ms |
5588 KB |
Output is correct |
75 |
Correct |
76 ms |
5588 KB |
Output is correct |
76 |
Correct |
103 ms |
5572 KB |
Output is correct |
77 |
Correct |
92 ms |
5588 KB |
Output is correct |
78 |
Correct |
81 ms |
5588 KB |
Output is correct |
79 |
Correct |
72 ms |
5588 KB |
Output is correct |
80 |
Correct |
104 ms |
5588 KB |
Output is correct |
81 |
Correct |
68 ms |
5588 KB |
Output is correct |
82 |
Correct |
73 ms |
5568 KB |
Output is correct |
83 |
Correct |
107 ms |
5588 KB |
Output is correct |
84 |
Correct |
99 ms |
5572 KB |
Output is correct |
85 |
Correct |
95 ms |
5588 KB |
Output is correct |
86 |
Correct |
98 ms |
5588 KB |
Output is correct |
87 |
Correct |
77 ms |
5588 KB |
Output is correct |
88 |
Correct |
109 ms |
5588 KB |
Output is correct |
89 |
Correct |
96 ms |
5588 KB |
Output is correct |
90 |
Correct |
78 ms |
5588 KB |
Output is correct |
91 |
Correct |
108 ms |
5588 KB |
Output is correct |
92 |
Correct |
105 ms |
5588 KB |
Output is correct |
93 |
Correct |
108 ms |
5588 KB |
Output is correct |