#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("q.gir","r",stdin);
// freopen("q.cik","w",stdout);
int n, L, ans = 0;
cin >> n >> L;
vector<int> X(n + 1),T(n + 1);
X[0] = 0;
T[0] = 0;
for(int i = 1; i <= n; i++)cin >> X[i];
for(int i = 1; i <= n; i++)cin >> T[i];
X.pb(L);
T.pb(0);
int dp[n + 1][n + 2][n + 1][2];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n + 1; j++){
for(int k = 0; k <= n; k++){
if(k == 0 && i == 0 && j == n + 1)dp[i][j][k][0] = dp[i][j][k][1] = 0;
else dp[i][j][k][0] = dp[i][j][k][1] = INF;
}
}
}
for(int cw = 0; cw <= n; cw++){
for(int ccw = n + 1; ccw > cw; ccw--){
for(int cnt = 0; cnt <= n; cnt++){
int cwT1 = INF, cwT2 = INF, ccwT1 = INF, ccwT2 = INF, cwT, ccwT;
if(cnt > 0){
if(cw != 0)cwT1 = dp[cw - 1][ccw][cnt - 1][1] + (X[cw] - X[cw - 1]);
if(cw != 0)cwT2 = dp[cw - 1][ccw][cnt - 1][0] + (L - X[ccw] + X[cw]);
if(ccw != n + 1)ccwT1 = dp[cw][ccw + 1][cnt - 1][1] + (X[cw] + L - X[ccw]);
if(ccw != n + 1)ccwT2 = dp[cw][ccw + 1][cnt - 1][0] + (X[ccw + 1] - X[ccw]);
cwT = min(cwT1, cwT2);
ccwT = min(ccwT1, ccwT2);
if(T[cw] >= cwT) dp[cw][ccw][cnt][1] = min(dp[cw][ccw][cnt][1], cwT);
if(T[ccw] >= ccwT) dp[cw][ccw][cnt][0] = min(dp[cw][ccw][cnt][0], ccwT);
}
cwT1 = INF, cwT2 = INF, ccwT1 = INF, ccwT2 = INF;
if(cw != 0)cwT1 = dp[cw - 1][ccw][cnt][1] + (X[cw] - X[cw - 1]);
if(cw != 0)cwT2 = dp[cw - 1][ccw][cnt][0] + (L - X[ccw] + X[cw]);
if(ccw != n + 1)ccwT1 = dp[cw][ccw + 1][cnt][1] + (X[cw] + L - X[ccw]);
if(ccw != n + 1)ccwT2 = dp[cw][ccw + 1][cnt][0] + (X[ccw + 1] - X[ccw]);
cwT = min(cwT1, cwT2);
ccwT = min(ccwT1, ccwT2);
dp[cw][ccw][cnt][1] = min(dp[cw][ccw][cnt][1], cwT);
dp[cw][ccw][cnt][0] = min(dp[cw][ccw][cnt][0], ccwT);
}
}
}
for(int i = 0; i <= n; i++){
for(int j = n + 1; j > i; j--){
for(int k = 0; k <= n; k++){
for(int q = 0; q < 2; q++){
if(dp[i][j][k][q] < 1e15) ans = max(ans, k);
}
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
380 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
4 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Correct |
87 ms |
92152 KB |
Output is correct |
19 |
Correct |
44 ms |
43768 KB |
Output is correct |
20 |
Correct |
22 ms |
17144 KB |
Output is correct |
21 |
Correct |
41 ms |
40056 KB |
Output is correct |
22 |
Correct |
58 ms |
59000 KB |
Output is correct |
23 |
Correct |
18 ms |
13432 KB |
Output is correct |
24 |
Correct |
13 ms |
9336 KB |
Output is correct |
25 |
Correct |
18 ms |
13048 KB |
Output is correct |
26 |
Correct |
7 ms |
3320 KB |
Output is correct |
27 |
Correct |
19 ms |
13944 KB |
Output is correct |
28 |
Correct |
12 ms |
8440 KB |
Output is correct |
29 |
Correct |
19 ms |
14328 KB |
Output is correct |
30 |
Correct |
14 ms |
10104 KB |
Output is correct |
31 |
Correct |
17 ms |
13048 KB |
Output is correct |
32 |
Correct |
9 ms |
5112 KB |
Output is correct |
33 |
Correct |
17 ms |
13048 KB |
Output is correct |
34 |
Correct |
7 ms |
2940 KB |
Output is correct |
35 |
Correct |
18 ms |
12792 KB |
Output is correct |
36 |
Correct |
10 ms |
4344 KB |
Output is correct |
37 |
Correct |
24 ms |
13820 KB |
Output is correct |
38 |
Correct |
9 ms |
5752 KB |
Output is correct |
39 |
Correct |
18 ms |
14712 KB |
Output is correct |
40 |
Correct |
10 ms |
6776 KB |
Output is correct |
41 |
Correct |
120 ms |
126200 KB |
Output is correct |
42 |
Correct |
69 ms |
69860 KB |
Output is correct |
43 |
Correct |
115 ms |
126200 KB |
Output is correct |
44 |
Correct |
67 ms |
68600 KB |
Output is correct |
45 |
Correct |
114 ms |
126200 KB |
Output is correct |
46 |
Correct |
73 ms |
69880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
380 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
380 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
4 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
87 ms |
92152 KB |
Output is correct |
37 |
Correct |
44 ms |
43768 KB |
Output is correct |
38 |
Correct |
22 ms |
17144 KB |
Output is correct |
39 |
Correct |
41 ms |
40056 KB |
Output is correct |
40 |
Correct |
58 ms |
59000 KB |
Output is correct |
41 |
Correct |
18 ms |
13432 KB |
Output is correct |
42 |
Correct |
13 ms |
9336 KB |
Output is correct |
43 |
Correct |
18 ms |
13048 KB |
Output is correct |
44 |
Correct |
7 ms |
3320 KB |
Output is correct |
45 |
Correct |
19 ms |
13944 KB |
Output is correct |
46 |
Correct |
12 ms |
8440 KB |
Output is correct |
47 |
Correct |
19 ms |
14328 KB |
Output is correct |
48 |
Correct |
14 ms |
10104 KB |
Output is correct |
49 |
Correct |
17 ms |
13048 KB |
Output is correct |
50 |
Correct |
9 ms |
5112 KB |
Output is correct |
51 |
Correct |
17 ms |
13048 KB |
Output is correct |
52 |
Correct |
7 ms |
2940 KB |
Output is correct |
53 |
Correct |
18 ms |
12792 KB |
Output is correct |
54 |
Correct |
10 ms |
4344 KB |
Output is correct |
55 |
Correct |
24 ms |
13820 KB |
Output is correct |
56 |
Correct |
9 ms |
5752 KB |
Output is correct |
57 |
Correct |
18 ms |
14712 KB |
Output is correct |
58 |
Correct |
10 ms |
6776 KB |
Output is correct |
59 |
Correct |
120 ms |
126200 KB |
Output is correct |
60 |
Correct |
69 ms |
69860 KB |
Output is correct |
61 |
Correct |
115 ms |
126200 KB |
Output is correct |
62 |
Correct |
67 ms |
68600 KB |
Output is correct |
63 |
Correct |
114 ms |
126200 KB |
Output is correct |
64 |
Correct |
73 ms |
69880 KB |
Output is correct |
65 |
Correct |
99 ms |
108280 KB |
Output is correct |
66 |
Correct |
89 ms |
95292 KB |
Output is correct |
67 |
Correct |
83 ms |
89080 KB |
Output is correct |
68 |
Correct |
77 ms |
79096 KB |
Output is correct |
69 |
Correct |
97 ms |
106616 KB |
Output is correct |
70 |
Correct |
94 ms |
99960 KB |
Output is correct |
71 |
Correct |
96 ms |
101624 KB |
Output is correct |
72 |
Correct |
98 ms |
103288 KB |
Output is correct |
73 |
Correct |
85 ms |
92280 KB |
Output is correct |
74 |
Correct |
80 ms |
83320 KB |
Output is correct |
75 |
Correct |
92 ms |
96888 KB |
Output is correct |
76 |
Correct |
114 ms |
118904 KB |
Output is correct |
77 |
Correct |
110 ms |
118776 KB |
Output is correct |
78 |
Correct |
78 ms |
80544 KB |
Output is correct |
79 |
Correct |
80 ms |
84856 KB |
Output is correct |
80 |
Correct |
107 ms |
115192 KB |
Output is correct |
81 |
Correct |
82 ms |
86136 KB |
Output is correct |
82 |
Correct |
86 ms |
93688 KB |
Output is correct |
83 |
Correct |
114 ms |
126292 KB |
Output is correct |
84 |
Correct |
97 ms |
100088 KB |
Output is correct |
85 |
Correct |
105 ms |
113528 KB |
Output is correct |
86 |
Correct |
105 ms |
110200 KB |
Output is correct |
87 |
Correct |
88 ms |
96888 KB |
Output is correct |
88 |
Correct |
116 ms |
128300 KB |
Output is correct |
89 |
Correct |
121 ms |
128120 KB |
Output is correct |
90 |
Correct |
91 ms |
98424 KB |
Output is correct |
91 |
Correct |
115 ms |
128120 KB |
Output is correct |
92 |
Correct |
114 ms |
128120 KB |
Output is correct |
93 |
Correct |
111 ms |
124280 KB |
Output is correct |