#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long n,l;
long long ans = 0;
const long long MAXN = 210;
long long dp[MAXN][MAXN][MAXN][5];
long long arr[MAXN];
long long t[MAXN];
long long check(long long x){
x+=(n+1);
x%=(n+1);
return x;
}
long long dist(long long from,long long to,long long way){
if(way == 0){
if(arr[to]>=arr[from]){
return arr[to]-arr[from];
}
return l-arr[from]+arr[to];
}else{
if(arr[from]>=arr[to]){
return arr[from]-arr[to];
}
return arr[from]+l-arr[to];
}
}
int main(){
cin>>n>>l;
for(long long i=0;i<=n;i++){
for(long long j=0;j<=n;j++){
for(long long k=0;k<=n;k++){
for(long long l=0;l<=4;l++){
dp[i][j][k][l] = 1e14;
}
}
}
}
dp[0][0][0][0] = 0;
dp[0][0][0][1] = 0;
for(long long i=1;i<=n;i++){
cin>>arr[i];
}
for(long long i=1;i<=n;i++){
cin>>t[i];
}
for(long long i=0;i<=n;i++){
for(long long len=0;len<=n;len++){
for(long long l=0;l<=n;l++){
long long r=check(l+len);
if(len == 0 && l==0){
r=0;
}else if(len == 0){
continue;
}
dp[i][l][r][0] = min(dp[i][l][r][0],dp[i][l][r][1]+dist(r,l,1));
dp[i][l][r][1] = min(dp[i][l][r][1],dp[i][l][r][0]+dist(l,r,0));
long long currl = dp[i][l][r][0];
long long currr = dp[i][l][r][1];
// cout<<len<<" "<<l<<" "<<r<<endl;
if(currl==1e14 && currr ==1e14){
continue;
}
ans = max(ans,i);
// cout<<currl<<" "<<currr<<endl;
if(currl+dist(l,check(r+1),0)<=t[check(r+1)]){
dp[i+1][l][check(r+1)][1] = min(dp[i+1][l][check(r+1)][1],currl+dist(l,check(r+1),0));
}else{
dp[i][l][check(r+1)][1] = min(dp[i][l][check(r+1)][1],currl+dist(l,check(r+1),0));
}
if(currr+dist(r,check(r+1),0)<=t[check(r+1)]){
dp[i+1][l][check(r+1)][1] = min(dp[i+1][l][check(r+1)][1],currr+dist(r,check(r+1),0));
}else{
dp[i][l][check(r+1)][1] = min(dp[i+1][l][check(r+1)][1],currr+dist(r,check(r+1),0));
}
if(currl+dist(l,check(l-1),1)<=t[check(l-1)]){
dp[i+1][check(l-1)][r][0]=min(dp[i+1][check(l-1)][r][0],currl+dist(l,check(l-1),1));
//cout<<i+1<<" "<<check(l-1)<<" "<<r<<endl;
}else{
dp[i][check(l-1)][r][0]= min(dp[i][check(l-1)][r][0],currl+dist(l,check(l-1),1));
}
if(currr+dist(r,check(l-1),1)<=t[check(l-1)]){
dp[i+1][check(l-1)][r][0] = min(dp[i+1][check(l-1)][r][0],currr+dist(r,check(l-1),1));
// cout<<check(l-1)<<" "<<r<<" "<<dp[i+1][check(l-1)][r][0]<<endl;
}else{
dp[i][check(l-1)][r][0] = min(dp[i][check(l-1)][r][0],currr+dist(r,check(l-1),1));
}
}
}
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
896 KB |
Output is correct |
9 |
Correct |
5 ms |
1152 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
1152 KB |
Output is correct |
13 |
Correct |
5 ms |
1152 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
768 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
896 KB |
Output is correct |
9 |
Correct |
5 ms |
1152 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
1152 KB |
Output is correct |
13 |
Correct |
5 ms |
1152 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
768 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1152 KB |
Output is correct |
18 |
Correct |
5 ms |
1408 KB |
Output is correct |
19 |
Correct |
5 ms |
896 KB |
Output is correct |
20 |
Correct |
5 ms |
1152 KB |
Output is correct |
21 |
Correct |
5 ms |
1408 KB |
Output is correct |
22 |
Correct |
5 ms |
768 KB |
Output is correct |
23 |
Correct |
5 ms |
1536 KB |
Output is correct |
24 |
Correct |
5 ms |
1280 KB |
Output is correct |
25 |
Correct |
5 ms |
1408 KB |
Output is correct |
26 |
Correct |
5 ms |
1408 KB |
Output is correct |
27 |
Correct |
5 ms |
768 KB |
Output is correct |
28 |
Correct |
5 ms |
768 KB |
Output is correct |
29 |
Correct |
6 ms |
1536 KB |
Output is correct |
30 |
Correct |
5 ms |
1536 KB |
Output is correct |
31 |
Correct |
5 ms |
1408 KB |
Output is correct |
32 |
Correct |
5 ms |
1280 KB |
Output is correct |
33 |
Correct |
5 ms |
1536 KB |
Output is correct |
34 |
Correct |
5 ms |
1536 KB |
Output is correct |
35 |
Correct |
5 ms |
1536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
896 KB |
Output is correct |
9 |
Correct |
5 ms |
1152 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
1152 KB |
Output is correct |
13 |
Correct |
5 ms |
1152 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
768 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1152 KB |
Output is correct |
18 |
Correct |
212 ms |
267256 KB |
Output is correct |
19 |
Correct |
123 ms |
161784 KB |
Output is correct |
20 |
Correct |
59 ms |
83576 KB |
Output is correct |
21 |
Correct |
111 ms |
152696 KB |
Output is correct |
22 |
Correct |
159 ms |
198268 KB |
Output is correct |
23 |
Correct |
53 ms |
68344 KB |
Output is correct |
24 |
Correct |
36 ms |
50432 KB |
Output is correct |
25 |
Correct |
48 ms |
66552 KB |
Output is correct |
26 |
Correct |
18 ms |
20736 KB |
Output is correct |
27 |
Correct |
55 ms |
70136 KB |
Output is correct |
28 |
Correct |
33 ms |
46080 KB |
Output is correct |
29 |
Incorrect |
52 ms |
71936 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
4 ms |
512 KB |
Output is correct |
3 |
Correct |
5 ms |
768 KB |
Output is correct |
4 |
Correct |
4 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
5 ms |
1152 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
896 KB |
Output is correct |
9 |
Correct |
5 ms |
1152 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
1152 KB |
Output is correct |
13 |
Correct |
5 ms |
1152 KB |
Output is correct |
14 |
Correct |
5 ms |
640 KB |
Output is correct |
15 |
Correct |
5 ms |
768 KB |
Output is correct |
16 |
Correct |
5 ms |
1152 KB |
Output is correct |
17 |
Correct |
5 ms |
1152 KB |
Output is correct |
18 |
Correct |
5 ms |
1408 KB |
Output is correct |
19 |
Correct |
5 ms |
896 KB |
Output is correct |
20 |
Correct |
5 ms |
1152 KB |
Output is correct |
21 |
Correct |
5 ms |
1408 KB |
Output is correct |
22 |
Correct |
5 ms |
768 KB |
Output is correct |
23 |
Correct |
5 ms |
1536 KB |
Output is correct |
24 |
Correct |
5 ms |
1280 KB |
Output is correct |
25 |
Correct |
5 ms |
1408 KB |
Output is correct |
26 |
Correct |
5 ms |
1408 KB |
Output is correct |
27 |
Correct |
5 ms |
768 KB |
Output is correct |
28 |
Correct |
5 ms |
768 KB |
Output is correct |
29 |
Correct |
6 ms |
1536 KB |
Output is correct |
30 |
Correct |
5 ms |
1536 KB |
Output is correct |
31 |
Correct |
5 ms |
1408 KB |
Output is correct |
32 |
Correct |
5 ms |
1280 KB |
Output is correct |
33 |
Correct |
5 ms |
1536 KB |
Output is correct |
34 |
Correct |
5 ms |
1536 KB |
Output is correct |
35 |
Correct |
5 ms |
1536 KB |
Output is correct |
36 |
Correct |
212 ms |
267256 KB |
Output is correct |
37 |
Correct |
123 ms |
161784 KB |
Output is correct |
38 |
Correct |
59 ms |
83576 KB |
Output is correct |
39 |
Correct |
111 ms |
152696 KB |
Output is correct |
40 |
Correct |
159 ms |
198268 KB |
Output is correct |
41 |
Correct |
53 ms |
68344 KB |
Output is correct |
42 |
Correct |
36 ms |
50432 KB |
Output is correct |
43 |
Correct |
48 ms |
66552 KB |
Output is correct |
44 |
Correct |
18 ms |
20736 KB |
Output is correct |
45 |
Correct |
55 ms |
70136 KB |
Output is correct |
46 |
Correct |
33 ms |
46080 KB |
Output is correct |
47 |
Incorrect |
52 ms |
71936 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |