#include <bits/stdc++.h>
#define x first
#define t second
using namespace std;
typedef pair<long long, long long> ii;
long long inf = (1LL << 48LL);
vector<ii> arr = {ii({0,-2})};
static long long memo[205][205][205];
long long n, L;
long long dp(int pos, int bound, int taken){
if(taken < 0) return inf;
if(pos == bound) return inf;
long long ans = inf;
if(pos == 0 && bound == 0) return inf;
if(pos == n+1 && bound == n+1) return inf;
if(pos == 0 && bound == n+1){
if(taken == 0) return 0;
else return inf;
}
if(pos == n+1 && bound == 0){
if(taken == 0) return 0;
else return inf;
}
if(pos == 0 || pos == n+1) return inf;
if(memo[pos][bound][taken] != -1) return memo[pos][bound][taken];
int pos2;
long long dPos, dCross;
if(pos < bound){
pos2 = pos-1;
if(pos2 == -1) pos2 = n+1;
}
else{
pos2 = pos+1;
if(pos2 == n+2) pos2 = 0;
}
if(pos > pos2) dPos = arr[pos].x - arr[pos2].x;
else dPos = arr[pos2].x - arr[pos].x;
///move from bound to pos
if(bound > pos){
dCross = L - (arr[bound].x - arr[pos].x);
}
else{
dCross = L - (arr[pos].x - arr[bound].x);
}
assert(dPos >= 0);
assert(dCross >= 0);
if(pos == 1 && bound == 0){
//cout << pos << " " << bound << " " << pos2 << " " << dPos << " " << dCross << "\n";
}
ans = min(ans, dp(pos2, bound, taken) + dPos);
ans = min(ans, dp(bound, pos2, taken) + dCross);
if(dp(pos2, bound, taken - 1) + dPos <= arr[pos].t){
ans = min(dp(pos2, bound, taken - 1) + dPos, ans);
}
if(dp(bound, pos2, taken - 1) + dCross <= arr[pos].t){
ans = min(dp(bound, pos2, taken - 1) + dCross, ans);
}
//if(pos == 2 && bound == 11 && taken == 0){
// cout << pos2 << " " << dPos << " " << dCross << "\n";
//}
//cout << pos << " " << bound << " " << taken << " " << ans << endl;
memo[pos][bound][taken] = ans;
return ans;
}
int main(){
//freopen("i.txt","r",stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> L;
for(int i = 0;i < n;i++){
arr.push_back(ii(0,0));
}
for(int i = 1;i <= n;i++) cin >> arr[i].x;
for(int i = 1;i <= n;i++) cin >> arr[i].t;
arr.push_back(ii(L,-2));
for(int i = 0;i <= n + 1;i++){
for(int j = 0;j <= n + 1;j++){
for(int k = 0;k <= n + 1;k++){
memo[i][j][k] = -1;
}
}
}
long long ANS = 0;
for(long long taken = 0;taken <= n;taken++){
for(int i = 0;i <= n + 1;i++){
for(int j = 0;j <= n + 1;j++){
long long DP = dp(i,j,taken);
if(DP < inf){
ANS = max(ANS, taken);
//if(taken == 6) cout << i << " " << j << " " << DP << '\n';
}
}
}
}
cout << ANS;
//cout << dp(10,11,6);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
6 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
6 ms |
768 KB |
Output is correct |
18 |
Correct |
6 ms |
768 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
768 KB |
Output is correct |
21 |
Correct |
5 ms |
768 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
896 KB |
Output is correct |
24 |
Correct |
5 ms |
768 KB |
Output is correct |
25 |
Correct |
5 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
744 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
896 KB |
Output is correct |
30 |
Correct |
6 ms |
1024 KB |
Output is correct |
31 |
Correct |
5 ms |
896 KB |
Output is correct |
32 |
Correct |
5 ms |
768 KB |
Output is correct |
33 |
Correct |
5 ms |
896 KB |
Output is correct |
34 |
Correct |
5 ms |
896 KB |
Output is correct |
35 |
Correct |
5 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
6 ms |
768 KB |
Output is correct |
18 |
Correct |
477 ms |
53632 KB |
Output is correct |
19 |
Correct |
184 ms |
32768 KB |
Output is correct |
20 |
Correct |
70 ms |
17784 KB |
Output is correct |
21 |
Correct |
162 ms |
30976 KB |
Output is correct |
22 |
Correct |
246 ms |
40048 KB |
Output is correct |
23 |
Correct |
61 ms |
15200 KB |
Output is correct |
24 |
Correct |
40 ms |
12024 KB |
Output is correct |
25 |
Correct |
52 ms |
14848 KB |
Output is correct |
26 |
Correct |
15 ms |
6016 KB |
Output is correct |
27 |
Correct |
57 ms |
15480 KB |
Output is correct |
28 |
Correct |
43 ms |
11256 KB |
Output is correct |
29 |
Correct |
56 ms |
15744 KB |
Output is correct |
30 |
Correct |
39 ms |
12544 KB |
Output is correct |
31 |
Correct |
53 ms |
14848 KB |
Output is correct |
32 |
Correct |
20 ms |
8064 KB |
Output is correct |
33 |
Correct |
49 ms |
14840 KB |
Output is correct |
34 |
Correct |
13 ms |
5632 KB |
Output is correct |
35 |
Correct |
54 ms |
14592 KB |
Output is correct |
36 |
Correct |
20 ms |
7168 KB |
Output is correct |
37 |
Correct |
53 ms |
15488 KB |
Output is correct |
38 |
Correct |
24 ms |
8704 KB |
Output is correct |
39 |
Correct |
59 ms |
16128 KB |
Output is correct |
40 |
Correct |
27 ms |
9600 KB |
Output is correct |
41 |
Correct |
494 ms |
65916 KB |
Output is correct |
42 |
Correct |
247 ms |
44672 KB |
Output is correct |
43 |
Correct |
504 ms |
66040 KB |
Output is correct |
44 |
Correct |
251 ms |
44160 KB |
Output is correct |
45 |
Correct |
532 ms |
66172 KB |
Output is correct |
46 |
Correct |
246 ms |
44672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
640 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
5 ms |
768 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
768 KB |
Output is correct |
17 |
Correct |
6 ms |
768 KB |
Output is correct |
18 |
Correct |
6 ms |
768 KB |
Output is correct |
19 |
Correct |
5 ms |
640 KB |
Output is correct |
20 |
Correct |
5 ms |
768 KB |
Output is correct |
21 |
Correct |
5 ms |
768 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
896 KB |
Output is correct |
24 |
Correct |
5 ms |
768 KB |
Output is correct |
25 |
Correct |
5 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
744 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
896 KB |
Output is correct |
30 |
Correct |
6 ms |
1024 KB |
Output is correct |
31 |
Correct |
5 ms |
896 KB |
Output is correct |
32 |
Correct |
5 ms |
768 KB |
Output is correct |
33 |
Correct |
5 ms |
896 KB |
Output is correct |
34 |
Correct |
5 ms |
896 KB |
Output is correct |
35 |
Correct |
5 ms |
904 KB |
Output is correct |
36 |
Correct |
477 ms |
53632 KB |
Output is correct |
37 |
Correct |
184 ms |
32768 KB |
Output is correct |
38 |
Correct |
70 ms |
17784 KB |
Output is correct |
39 |
Correct |
162 ms |
30976 KB |
Output is correct |
40 |
Correct |
246 ms |
40048 KB |
Output is correct |
41 |
Correct |
61 ms |
15200 KB |
Output is correct |
42 |
Correct |
40 ms |
12024 KB |
Output is correct |
43 |
Correct |
52 ms |
14848 KB |
Output is correct |
44 |
Correct |
15 ms |
6016 KB |
Output is correct |
45 |
Correct |
57 ms |
15480 KB |
Output is correct |
46 |
Correct |
43 ms |
11256 KB |
Output is correct |
47 |
Correct |
56 ms |
15744 KB |
Output is correct |
48 |
Correct |
39 ms |
12544 KB |
Output is correct |
49 |
Correct |
53 ms |
14848 KB |
Output is correct |
50 |
Correct |
20 ms |
8064 KB |
Output is correct |
51 |
Correct |
49 ms |
14840 KB |
Output is correct |
52 |
Correct |
13 ms |
5632 KB |
Output is correct |
53 |
Correct |
54 ms |
14592 KB |
Output is correct |
54 |
Correct |
20 ms |
7168 KB |
Output is correct |
55 |
Correct |
53 ms |
15488 KB |
Output is correct |
56 |
Correct |
24 ms |
8704 KB |
Output is correct |
57 |
Correct |
59 ms |
16128 KB |
Output is correct |
58 |
Correct |
27 ms |
9600 KB |
Output is correct |
59 |
Correct |
494 ms |
65916 KB |
Output is correct |
60 |
Correct |
247 ms |
44672 KB |
Output is correct |
61 |
Correct |
504 ms |
66040 KB |
Output is correct |
62 |
Correct |
251 ms |
44160 KB |
Output is correct |
63 |
Correct |
532 ms |
66172 KB |
Output is correct |
64 |
Correct |
246 ms |
44672 KB |
Output is correct |
65 |
Correct |
439 ms |
59768 KB |
Output is correct |
66 |
Correct |
349 ms |
54784 KB |
Output is correct |
67 |
Correct |
324 ms |
52480 KB |
Output is correct |
68 |
Correct |
295 ms |
48512 KB |
Output is correct |
69 |
Correct |
401 ms |
59008 KB |
Output is correct |
70 |
Correct |
396 ms |
56692 KB |
Output is correct |
71 |
Correct |
361 ms |
57344 KB |
Output is correct |
72 |
Correct |
416 ms |
57976 KB |
Output is correct |
73 |
Correct |
325 ms |
53632 KB |
Output is correct |
74 |
Correct |
340 ms |
50232 KB |
Output is correct |
75 |
Correct |
363 ms |
55444 KB |
Output is correct |
76 |
Correct |
510 ms |
63480 KB |
Output is correct |
77 |
Correct |
435 ms |
63356 KB |
Output is correct |
78 |
Correct |
307 ms |
49020 KB |
Output is correct |
79 |
Correct |
300 ms |
50688 KB |
Output is correct |
80 |
Correct |
497 ms |
62200 KB |
Output is correct |
81 |
Correct |
369 ms |
51372 KB |
Output is correct |
82 |
Correct |
347 ms |
54136 KB |
Output is correct |
83 |
Correct |
482 ms |
65920 KB |
Output is correct |
84 |
Correct |
376 ms |
56576 KB |
Output is correct |
85 |
Correct |
415 ms |
61560 KB |
Output is correct |
86 |
Correct |
397 ms |
60288 KB |
Output is correct |
87 |
Correct |
344 ms |
55424 KB |
Output is correct |
88 |
Correct |
532 ms |
66680 KB |
Output is correct |
89 |
Correct |
518 ms |
66808 KB |
Output is correct |
90 |
Correct |
348 ms |
55936 KB |
Output is correct |
91 |
Correct |
513 ms |
66812 KB |
Output is correct |
92 |
Correct |
511 ms |
66680 KB |
Output is correct |
93 |
Correct |
507 ms |
65380 KB |
Output is correct |