#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int INF = 1e18;
const int MAX_N = 202;
int N, L;
int X[MAX_N], T[MAX_N];
pii dp[MAX_N][MAX_N][MAX_N];
int dist(int a, int b){
if(a>b){
return (b-a+L)%L;
}
return a-b;
}
void push_val(int left, int right, int has){
int sz = dist(X[left],X[right]);
dp[left][right][has].first = min(dp[left][right][has].first, dp[left][right][has].second+sz);
dp[left][right][has].second = min(dp[left][right][has].second, dp[left][right][has].first+sz);
if(left-right>1){
int new_time = dp[left][right][has].first + abs(X[left-1] - X[left]);
if(new_time<=T[left-1]){
dp[left-1][right][has+1].first = min(dp[left-1][right][has+1].first , new_time);
}
else{
dp[left-1][right][has].first = min(dp[left-1][right][has].first , new_time);
}
new_time = dp[left][right][has].second + abs(X[right+1] - X[right]);
if(new_time<=T[right+1]){
dp[left][right+1][has+1].second = min(dp[left][right+1][has+1].second , new_time);
}
else{
dp[left][right+1][has].second = min(dp[left][right+1][has].second , new_time);
}
}
}
signed main(){
fill(&dp[0][0][0], &dp[MAX_N-1][MAX_N-1][MAX_N-1] +1, pii(INF, INF));
cin>>N>>L;
N++;
X[0]= 0;
T[0] = -1;
for(int i = 1; i<N; i++){
cin>>X[i];
}
for(int i =1; i<N; i++){
cin>>T[i];
}
X[N] = L;
T[N] = -1;
dp[N][0][0] = pii(0, 0);
for(int l = N; l>0; l--){
for(int r = 0; r<l; r++){
for(int has = 0; has<N; has++){
push_val(l, r, has);
//cout<<l<<" "<<r<<" "<<has<<" "<<dp[l][r][has].first<<" "<<dp[l][r][has].second<<endl;
}
}
}
int res =0;
for(int l = N; l>0; l--){
for(int r = 0; r<l; r++){
for(int has = 0; has<N; has++){
if(dp[l][r][has].first<INF || dp[l][r][has].second<INF){
res = max(res, has);
}
}
}
}
cout<<res<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
129360 KB |
Output is correct |
2 |
Correct |
18 ms |
129368 KB |
Output is correct |
3 |
Correct |
18 ms |
129368 KB |
Output is correct |
4 |
Correct |
19 ms |
129372 KB |
Output is correct |
5 |
Correct |
18 ms |
129368 KB |
Output is correct |
6 |
Correct |
18 ms |
129372 KB |
Output is correct |
7 |
Correct |
19 ms |
129372 KB |
Output is correct |
8 |
Correct |
18 ms |
129368 KB |
Output is correct |
9 |
Correct |
18 ms |
129368 KB |
Output is correct |
10 |
Correct |
18 ms |
129368 KB |
Output is correct |
11 |
Correct |
18 ms |
129368 KB |
Output is correct |
12 |
Correct |
18 ms |
129360 KB |
Output is correct |
13 |
Correct |
18 ms |
129368 KB |
Output is correct |
14 |
Correct |
18 ms |
129368 KB |
Output is correct |
15 |
Correct |
18 ms |
129372 KB |
Output is correct |
16 |
Correct |
18 ms |
129268 KB |
Output is correct |
17 |
Correct |
18 ms |
129368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
129360 KB |
Output is correct |
2 |
Correct |
18 ms |
129368 KB |
Output is correct |
3 |
Correct |
18 ms |
129368 KB |
Output is correct |
4 |
Correct |
19 ms |
129372 KB |
Output is correct |
5 |
Correct |
18 ms |
129368 KB |
Output is correct |
6 |
Correct |
18 ms |
129372 KB |
Output is correct |
7 |
Correct |
19 ms |
129372 KB |
Output is correct |
8 |
Correct |
18 ms |
129368 KB |
Output is correct |
9 |
Correct |
18 ms |
129368 KB |
Output is correct |
10 |
Correct |
18 ms |
129368 KB |
Output is correct |
11 |
Correct |
18 ms |
129368 KB |
Output is correct |
12 |
Correct |
18 ms |
129360 KB |
Output is correct |
13 |
Correct |
18 ms |
129368 KB |
Output is correct |
14 |
Correct |
18 ms |
129368 KB |
Output is correct |
15 |
Correct |
18 ms |
129372 KB |
Output is correct |
16 |
Correct |
18 ms |
129268 KB |
Output is correct |
17 |
Correct |
18 ms |
129368 KB |
Output is correct |
18 |
Correct |
20 ms |
129628 KB |
Output is correct |
19 |
Correct |
18 ms |
129368 KB |
Output is correct |
20 |
Correct |
19 ms |
129368 KB |
Output is correct |
21 |
Correct |
18 ms |
129368 KB |
Output is correct |
22 |
Correct |
18 ms |
129368 KB |
Output is correct |
23 |
Correct |
18 ms |
129368 KB |
Output is correct |
24 |
Correct |
18 ms |
129368 KB |
Output is correct |
25 |
Correct |
18 ms |
129360 KB |
Output is correct |
26 |
Correct |
18 ms |
129360 KB |
Output is correct |
27 |
Correct |
19 ms |
129368 KB |
Output is correct |
28 |
Correct |
18 ms |
129264 KB |
Output is correct |
29 |
Correct |
18 ms |
129368 KB |
Output is correct |
30 |
Correct |
18 ms |
129368 KB |
Output is correct |
31 |
Correct |
19 ms |
129368 KB |
Output is correct |
32 |
Correct |
18 ms |
129368 KB |
Output is correct |
33 |
Correct |
20 ms |
129624 KB |
Output is correct |
34 |
Correct |
18 ms |
129268 KB |
Output is correct |
35 |
Correct |
18 ms |
129368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
129360 KB |
Output is correct |
2 |
Correct |
18 ms |
129368 KB |
Output is correct |
3 |
Correct |
18 ms |
129368 KB |
Output is correct |
4 |
Correct |
19 ms |
129372 KB |
Output is correct |
5 |
Correct |
18 ms |
129368 KB |
Output is correct |
6 |
Correct |
18 ms |
129372 KB |
Output is correct |
7 |
Correct |
19 ms |
129372 KB |
Output is correct |
8 |
Correct |
18 ms |
129368 KB |
Output is correct |
9 |
Correct |
18 ms |
129368 KB |
Output is correct |
10 |
Correct |
18 ms |
129368 KB |
Output is correct |
11 |
Correct |
18 ms |
129368 KB |
Output is correct |
12 |
Correct |
18 ms |
129360 KB |
Output is correct |
13 |
Correct |
18 ms |
129368 KB |
Output is correct |
14 |
Correct |
18 ms |
129368 KB |
Output is correct |
15 |
Correct |
18 ms |
129372 KB |
Output is correct |
16 |
Correct |
18 ms |
129268 KB |
Output is correct |
17 |
Correct |
18 ms |
129368 KB |
Output is correct |
18 |
Correct |
46 ms |
129368 KB |
Output is correct |
19 |
Correct |
34 ms |
129452 KB |
Output is correct |
20 |
Correct |
25 ms |
129368 KB |
Output is correct |
21 |
Correct |
35 ms |
129372 KB |
Output is correct |
22 |
Correct |
39 ms |
129448 KB |
Output is correct |
23 |
Correct |
24 ms |
129304 KB |
Output is correct |
24 |
Correct |
22 ms |
129372 KB |
Output is correct |
25 |
Correct |
23 ms |
129428 KB |
Output is correct |
26 |
Correct |
19 ms |
129264 KB |
Output is correct |
27 |
Correct |
24 ms |
129260 KB |
Output is correct |
28 |
Correct |
21 ms |
129368 KB |
Output is correct |
29 |
Correct |
23 ms |
129368 KB |
Output is correct |
30 |
Correct |
22 ms |
129368 KB |
Output is correct |
31 |
Correct |
24 ms |
129376 KB |
Output is correct |
32 |
Correct |
22 ms |
129880 KB |
Output is correct |
33 |
Correct |
23 ms |
129368 KB |
Output is correct |
34 |
Correct |
19 ms |
129372 KB |
Output is correct |
35 |
Correct |
24 ms |
129368 KB |
Output is correct |
36 |
Correct |
20 ms |
129368 KB |
Output is correct |
37 |
Correct |
24 ms |
129368 KB |
Output is correct |
38 |
Correct |
20 ms |
129360 KB |
Output is correct |
39 |
Correct |
23 ms |
129368 KB |
Output is correct |
40 |
Correct |
21 ms |
129368 KB |
Output is correct |
41 |
Correct |
53 ms |
129360 KB |
Output is correct |
42 |
Correct |
41 ms |
129368 KB |
Output is correct |
43 |
Correct |
55 ms |
129340 KB |
Output is correct |
44 |
Correct |
40 ms |
129368 KB |
Output is correct |
45 |
Correct |
58 ms |
129360 KB |
Output is correct |
46 |
Correct |
41 ms |
129360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
129360 KB |
Output is correct |
2 |
Correct |
18 ms |
129368 KB |
Output is correct |
3 |
Correct |
18 ms |
129368 KB |
Output is correct |
4 |
Correct |
19 ms |
129372 KB |
Output is correct |
5 |
Correct |
18 ms |
129368 KB |
Output is correct |
6 |
Correct |
18 ms |
129372 KB |
Output is correct |
7 |
Correct |
19 ms |
129372 KB |
Output is correct |
8 |
Correct |
18 ms |
129368 KB |
Output is correct |
9 |
Correct |
18 ms |
129368 KB |
Output is correct |
10 |
Correct |
18 ms |
129368 KB |
Output is correct |
11 |
Correct |
18 ms |
129368 KB |
Output is correct |
12 |
Correct |
18 ms |
129360 KB |
Output is correct |
13 |
Correct |
18 ms |
129368 KB |
Output is correct |
14 |
Correct |
18 ms |
129368 KB |
Output is correct |
15 |
Correct |
18 ms |
129372 KB |
Output is correct |
16 |
Correct |
18 ms |
129268 KB |
Output is correct |
17 |
Correct |
18 ms |
129368 KB |
Output is correct |
18 |
Correct |
20 ms |
129628 KB |
Output is correct |
19 |
Correct |
18 ms |
129368 KB |
Output is correct |
20 |
Correct |
19 ms |
129368 KB |
Output is correct |
21 |
Correct |
18 ms |
129368 KB |
Output is correct |
22 |
Correct |
18 ms |
129368 KB |
Output is correct |
23 |
Correct |
18 ms |
129368 KB |
Output is correct |
24 |
Correct |
18 ms |
129368 KB |
Output is correct |
25 |
Correct |
18 ms |
129360 KB |
Output is correct |
26 |
Correct |
18 ms |
129360 KB |
Output is correct |
27 |
Correct |
19 ms |
129368 KB |
Output is correct |
28 |
Correct |
18 ms |
129264 KB |
Output is correct |
29 |
Correct |
18 ms |
129368 KB |
Output is correct |
30 |
Correct |
18 ms |
129368 KB |
Output is correct |
31 |
Correct |
19 ms |
129368 KB |
Output is correct |
32 |
Correct |
18 ms |
129368 KB |
Output is correct |
33 |
Correct |
20 ms |
129624 KB |
Output is correct |
34 |
Correct |
18 ms |
129268 KB |
Output is correct |
35 |
Correct |
18 ms |
129368 KB |
Output is correct |
36 |
Correct |
46 ms |
129368 KB |
Output is correct |
37 |
Correct |
34 ms |
129452 KB |
Output is correct |
38 |
Correct |
25 ms |
129368 KB |
Output is correct |
39 |
Correct |
35 ms |
129372 KB |
Output is correct |
40 |
Correct |
39 ms |
129448 KB |
Output is correct |
41 |
Correct |
24 ms |
129304 KB |
Output is correct |
42 |
Correct |
22 ms |
129372 KB |
Output is correct |
43 |
Correct |
23 ms |
129428 KB |
Output is correct |
44 |
Correct |
19 ms |
129264 KB |
Output is correct |
45 |
Correct |
24 ms |
129260 KB |
Output is correct |
46 |
Correct |
21 ms |
129368 KB |
Output is correct |
47 |
Correct |
23 ms |
129368 KB |
Output is correct |
48 |
Correct |
22 ms |
129368 KB |
Output is correct |
49 |
Correct |
24 ms |
129376 KB |
Output is correct |
50 |
Correct |
22 ms |
129880 KB |
Output is correct |
51 |
Correct |
23 ms |
129368 KB |
Output is correct |
52 |
Correct |
19 ms |
129372 KB |
Output is correct |
53 |
Correct |
24 ms |
129368 KB |
Output is correct |
54 |
Correct |
20 ms |
129368 KB |
Output is correct |
55 |
Correct |
24 ms |
129368 KB |
Output is correct |
56 |
Correct |
20 ms |
129360 KB |
Output is correct |
57 |
Correct |
23 ms |
129368 KB |
Output is correct |
58 |
Correct |
21 ms |
129368 KB |
Output is correct |
59 |
Correct |
53 ms |
129360 KB |
Output is correct |
60 |
Correct |
41 ms |
129368 KB |
Output is correct |
61 |
Correct |
55 ms |
129340 KB |
Output is correct |
62 |
Correct |
40 ms |
129368 KB |
Output is correct |
63 |
Correct |
58 ms |
129360 KB |
Output is correct |
64 |
Correct |
41 ms |
129360 KB |
Output is correct |
65 |
Correct |
51 ms |
129368 KB |
Output is correct |
66 |
Correct |
47 ms |
129624 KB |
Output is correct |
67 |
Correct |
46 ms |
129368 KB |
Output is correct |
68 |
Correct |
45 ms |
129368 KB |
Output is correct |
69 |
Correct |
49 ms |
129452 KB |
Output is correct |
70 |
Correct |
46 ms |
129368 KB |
Output is correct |
71 |
Correct |
46 ms |
129368 KB |
Output is correct |
72 |
Correct |
49 ms |
129368 KB |
Output is correct |
73 |
Correct |
46 ms |
129368 KB |
Output is correct |
74 |
Correct |
43 ms |
129360 KB |
Output is correct |
75 |
Correct |
46 ms |
129372 KB |
Output is correct |
76 |
Correct |
52 ms |
129368 KB |
Output is correct |
77 |
Correct |
52 ms |
129368 KB |
Output is correct |
78 |
Correct |
43 ms |
129372 KB |
Output is correct |
79 |
Correct |
45 ms |
129368 KB |
Output is correct |
80 |
Correct |
51 ms |
129368 KB |
Output is correct |
81 |
Correct |
44 ms |
129368 KB |
Output is correct |
82 |
Correct |
46 ms |
129368 KB |
Output is correct |
83 |
Correct |
54 ms |
129368 KB |
Output is correct |
84 |
Correct |
50 ms |
129492 KB |
Output is correct |
85 |
Correct |
50 ms |
129448 KB |
Output is correct |
86 |
Correct |
50 ms |
129368 KB |
Output is correct |
87 |
Correct |
45 ms |
129372 KB |
Output is correct |
88 |
Correct |
54 ms |
129368 KB |
Output is correct |
89 |
Correct |
56 ms |
129456 KB |
Output is correct |
90 |
Correct |
48 ms |
129372 KB |
Output is correct |
91 |
Correct |
55 ms |
129360 KB |
Output is correct |
92 |
Correct |
54 ms |
129372 KB |
Output is correct |
93 |
Correct |
53 ms |
129372 KB |
Output is correct |