#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=205, INF=1e18;
int dp[N][N][2][N];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, L; cin >> n >> L;
for(int i=0; i<=n+1; i++){
for(int l=0; l<=n+1; l++){
for(int j=0; j<2; j++){
for(int x=0; x<=n+1; x++){
dp[i][l][j][x] = INF;
}
}
}
}
vector<int> x(n), t(n);
for(auto &i: x) cin >> i;
for(auto &i: t) cin >> i;
dp[0][0][0][(t[0]>=x[0])]=dp[0][0][1][(t[0]>=x[0])]=x[0];
dp[n-1][n-1][0][(t[n-1]>=(L-x[n-1]))]=dp[n-1][n-1][1][(t[n-1]>=(L-x[n-1]))]=L-x[n-1];
auto val=[&](int a, int b){
int dis;
if(a==b) return INF;
if(b<a) dis=x[b]+L-x[a];
else dis=x[b]-x[a];
if(a<b) dis=min(dis, x[a]+L-x[b]);
else dis=min(dis, x[a]-x[b]);
return dis;
};
auto m=[&](int a){
a%=n; a+=n; a%=n;
return a;
};
int ans=max(t[0]>=x[0], t[n-1]>=(L-x[n-1]));
for(int i=0; i<n; i++){
for(int l=0; l<n; l++){
for(int j=0; j<2; j++){
for(int x=0; x<n; x++){
int r=m(l+i);
int v=dp[l][r][j][x];
if(v==INF||m(l-1)==r||m(r+1)==l) continue;
int dis=val((j==0?l:r), m(l-1));
int nex=x+((v+dis)<=t[m(l-1)]);
ans=max(ans, nex);
dp[m(l-1)][r][0][nex]=min(dp[m(l-1)][r][0][nex], v+dis);
dis=val((j==0?l:r), m(r+1));
nex=x+((v+dis)<=t[m(r+1)]);
ans=max(ans, nex);
dp[l][m(r+1)][1][nex]=min(dp[l][m(r+1)][1][nex], v+dis);
}
}
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
8536 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
4 ms |
8948 KB |
Output is correct |
9 |
Correct |
2 ms |
10840 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
10704 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
8536 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
4 ms |
8948 KB |
Output is correct |
9 |
Correct |
2 ms |
10840 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
10704 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
10840 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
12636 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10752 KB |
Output is correct |
26 |
Correct |
2 ms |
10584 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
12636 KB |
Output is correct |
30 |
Correct |
2 ms |
12636 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
1 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
2 ms |
12636 KB |
Output is correct |
35 |
Correct |
2 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
8536 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
4 ms |
8948 KB |
Output is correct |
9 |
Correct |
2 ms |
10840 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
10704 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
102 ms |
119516 KB |
Output is correct |
19 |
Correct |
38 ms |
94808 KB |
Output is correct |
20 |
Correct |
19 ms |
68188 KB |
Output is correct |
21 |
Correct |
32 ms |
90716 KB |
Output is correct |
22 |
Correct |
46 ms |
103004 KB |
Output is correct |
23 |
Correct |
20 ms |
64088 KB |
Output is correct |
24 |
Correct |
12 ms |
55900 KB |
Output is correct |
25 |
Correct |
19 ms |
62328 KB |
Output is correct |
26 |
Correct |
7 ms |
39516 KB |
Output is correct |
27 |
Correct |
20 ms |
64092 KB |
Output is correct |
28 |
Correct |
11 ms |
53988 KB |
Output is correct |
29 |
Correct |
17 ms |
64092 KB |
Output is correct |
30 |
Correct |
12 ms |
57944 KB |
Output is correct |
31 |
Correct |
17 ms |
62044 KB |
Output is correct |
32 |
Correct |
9 ms |
45656 KB |
Output is correct |
33 |
Correct |
17 ms |
62044 KB |
Output is correct |
34 |
Correct |
6 ms |
37468 KB |
Output is correct |
35 |
Correct |
14 ms |
62296 KB |
Output is correct |
36 |
Correct |
7 ms |
43612 KB |
Output is correct |
37 |
Correct |
15 ms |
64212 KB |
Output is correct |
38 |
Correct |
9 ms |
47708 KB |
Output is correct |
39 |
Correct |
15 ms |
66140 KB |
Output is correct |
40 |
Correct |
9 ms |
49756 KB |
Output is correct |
41 |
Correct |
88 ms |
133828 KB |
Output is correct |
42 |
Correct |
29 ms |
109148 KB |
Output is correct |
43 |
Correct |
87 ms |
134000 KB |
Output is correct |
44 |
Correct |
26 ms |
109144 KB |
Output is correct |
45 |
Correct |
83 ms |
133968 KB |
Output is correct |
46 |
Correct |
27 ms |
109144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
8536 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6488 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
4 ms |
8948 KB |
Output is correct |
9 |
Correct |
2 ms |
10840 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
10704 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
3 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
2 ms |
10840 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
2 ms |
12636 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10752 KB |
Output is correct |
26 |
Correct |
2 ms |
10584 KB |
Output is correct |
27 |
Correct |
1 ms |
6492 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
12636 KB |
Output is correct |
30 |
Correct |
2 ms |
12636 KB |
Output is correct |
31 |
Correct |
2 ms |
10588 KB |
Output is correct |
32 |
Correct |
1 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
2 ms |
12636 KB |
Output is correct |
35 |
Correct |
2 ms |
12636 KB |
Output is correct |
36 |
Correct |
102 ms |
119516 KB |
Output is correct |
37 |
Correct |
38 ms |
94808 KB |
Output is correct |
38 |
Correct |
19 ms |
68188 KB |
Output is correct |
39 |
Correct |
32 ms |
90716 KB |
Output is correct |
40 |
Correct |
46 ms |
103004 KB |
Output is correct |
41 |
Correct |
20 ms |
64088 KB |
Output is correct |
42 |
Correct |
12 ms |
55900 KB |
Output is correct |
43 |
Correct |
19 ms |
62328 KB |
Output is correct |
44 |
Correct |
7 ms |
39516 KB |
Output is correct |
45 |
Correct |
20 ms |
64092 KB |
Output is correct |
46 |
Correct |
11 ms |
53988 KB |
Output is correct |
47 |
Correct |
17 ms |
64092 KB |
Output is correct |
48 |
Correct |
12 ms |
57944 KB |
Output is correct |
49 |
Correct |
17 ms |
62044 KB |
Output is correct |
50 |
Correct |
9 ms |
45656 KB |
Output is correct |
51 |
Correct |
17 ms |
62044 KB |
Output is correct |
52 |
Correct |
6 ms |
37468 KB |
Output is correct |
53 |
Correct |
14 ms |
62296 KB |
Output is correct |
54 |
Correct |
7 ms |
43612 KB |
Output is correct |
55 |
Correct |
15 ms |
64212 KB |
Output is correct |
56 |
Correct |
9 ms |
47708 KB |
Output is correct |
57 |
Correct |
15 ms |
66140 KB |
Output is correct |
58 |
Correct |
9 ms |
49756 KB |
Output is correct |
59 |
Correct |
88 ms |
133828 KB |
Output is correct |
60 |
Correct |
29 ms |
109148 KB |
Output is correct |
61 |
Correct |
87 ms |
134000 KB |
Output is correct |
62 |
Correct |
26 ms |
109144 KB |
Output is correct |
63 |
Correct |
83 ms |
133968 KB |
Output is correct |
64 |
Correct |
27 ms |
109144 KB |
Output is correct |
65 |
Correct |
71 ms |
127836 KB |
Output is correct |
66 |
Correct |
66 ms |
121692 KB |
Output is correct |
67 |
Correct |
59 ms |
119640 KB |
Output is correct |
68 |
Correct |
53 ms |
115544 KB |
Output is correct |
69 |
Correct |
70 ms |
125780 KB |
Output is correct |
70 |
Correct |
73 ms |
123744 KB |
Output is correct |
71 |
Correct |
65 ms |
123988 KB |
Output is correct |
72 |
Correct |
77 ms |
125776 KB |
Output is correct |
73 |
Correct |
49 ms |
119640 KB |
Output is correct |
74 |
Correct |
61 ms |
115544 KB |
Output is correct |
75 |
Correct |
63 ms |
121692 KB |
Output is correct |
76 |
Correct |
91 ms |
132180 KB |
Output is correct |
77 |
Correct |
73 ms |
131928 KB |
Output is correct |
78 |
Correct |
61 ms |
115548 KB |
Output is correct |
79 |
Correct |
60 ms |
117592 KB |
Output is correct |
80 |
Correct |
86 ms |
129872 KB |
Output is correct |
81 |
Correct |
61 ms |
117588 KB |
Output is correct |
82 |
Correct |
49 ms |
121688 KB |
Output is correct |
83 |
Correct |
77 ms |
134004 KB |
Output is correct |
84 |
Correct |
52 ms |
123740 KB |
Output is correct |
85 |
Correct |
62 ms |
130152 KB |
Output is correct |
86 |
Correct |
56 ms |
127832 KB |
Output is correct |
87 |
Correct |
66 ms |
121688 KB |
Output is correct |
88 |
Correct |
105 ms |
134008 KB |
Output is correct |
89 |
Correct |
87 ms |
133968 KB |
Output is correct |
90 |
Correct |
33 ms |
123736 KB |
Output is correct |
91 |
Correct |
101 ms |
134004 KB |
Output is correct |
92 |
Correct |
83 ms |
134004 KB |
Output is correct |
93 |
Correct |
38 ms |
133980 KB |
Output is correct |