#include <bits/stdc++.h>
using namespace std;
long long int dp[205][205][205][2];
int n,L,x[400],t[400];
const long long int INF = 1e18;
int dist(int l,int r){
if(r >= l)return x[r] - x[l];
return L-x[l] + x[r];
}
int main()
{
cin>>n>>L;
for(int i=1;i<=n;i++)cin>>x[i];
for(int i=1;i<=n;i++)cin>>t[i];
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++)
for(int k=0;k<=n+1;k++)dp[i][j][k][0] = dp[i][j][k][1] = INF;
}
t[0] = -1;
dp[0][0][0][0] = 0;
n++;
int ans = 0;
for(int i=0;i<n;i++){
for(int l=0;l<n;l++){
for(int k=0;k<=n;k++){
int r = (l+i)%n;
for(int c=0;c<2;c++){
if(dp[l][r][k][c] == INF)continue;
//cout<<l<<" "<<r<<" "<<k<<" "<<c<<" "<<dp[l][r][k][c]<<'\n';
ans = max(ans,k);
int s = c?r:l;
int ln = (l-1+n)%n;
int d = dist(ln,s);
long long int v = dp[l][r][k][c] + d;
dp[ln][r][k][0] = min(dp[ln][r][k][0],v);
if(t[ln] >= v)dp[ln][r][k+1][0] = min(dp[ln][r][k+1][0],v);
int rn = (r+1)%n;
d = dist(s,rn);
v = dp[l][r][k][c] + d;
dp[l][rn][k][1] = min(dp[l][rn][k][1],v);
if(t[rn] >= v)dp[l][rn][k+1][1] = min(dp[l][rn][k+1][1],v);
}
}
}
}
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
552 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
0 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
552 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
0 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
684 KB |
Output is correct |
20 |
Correct |
1 ms |
812 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
844 KB |
Output is correct |
25 |
Correct |
1 ms |
972 KB |
Output is correct |
26 |
Correct |
1 ms |
940 KB |
Output is correct |
27 |
Correct |
1 ms |
560 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
1 ms |
1100 KB |
Output is correct |
31 |
Correct |
1 ms |
972 KB |
Output is correct |
32 |
Correct |
1 ms |
940 KB |
Output is correct |
33 |
Correct |
1 ms |
1100 KB |
Output is correct |
34 |
Correct |
1 ms |
1100 KB |
Output is correct |
35 |
Correct |
1 ms |
1064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
552 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
0 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
18 |
Correct |
101 ms |
104916 KB |
Output is correct |
19 |
Correct |
63 ms |
63664 KB |
Output is correct |
20 |
Correct |
28 ms |
33868 KB |
Output is correct |
21 |
Correct |
51 ms |
60100 KB |
Output is correct |
22 |
Correct |
72 ms |
78020 KB |
Output is correct |
23 |
Correct |
26 ms |
28928 KB |
Output is correct |
24 |
Correct |
14 ms |
22604 KB |
Output is correct |
25 |
Correct |
25 ms |
28236 KB |
Output is correct |
26 |
Correct |
6 ms |
10828 KB |
Output is correct |
27 |
Correct |
26 ms |
29516 KB |
Output is correct |
28 |
Correct |
12 ms |
21060 KB |
Output is correct |
29 |
Correct |
24 ms |
30168 KB |
Output is correct |
30 |
Correct |
13 ms |
23664 KB |
Output is correct |
31 |
Correct |
21 ms |
28304 KB |
Output is correct |
32 |
Correct |
10 ms |
14796 KB |
Output is correct |
33 |
Correct |
21 ms |
28236 KB |
Output is correct |
34 |
Correct |
5 ms |
10060 KB |
Output is correct |
35 |
Correct |
17 ms |
27724 KB |
Output is correct |
36 |
Correct |
7 ms |
13200 KB |
Output is correct |
37 |
Correct |
18 ms |
29516 KB |
Output is correct |
38 |
Correct |
10 ms |
16204 KB |
Output is correct |
39 |
Correct |
18 ms |
30716 KB |
Output is correct |
40 |
Correct |
10 ms |
17996 KB |
Output is correct |
41 |
Correct |
160 ms |
129444 KB |
Output is correct |
42 |
Correct |
47 ms |
87116 KB |
Output is correct |
43 |
Correct |
160 ms |
129444 KB |
Output is correct |
44 |
Correct |
45 ms |
86136 KB |
Output is correct |
45 |
Correct |
164 ms |
129444 KB |
Output is correct |
46 |
Correct |
53 ms |
87176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
552 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
844 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
844 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
0 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
844 KB |
Output is correct |
17 |
Correct |
1 ms |
844 KB |
Output is correct |
18 |
Correct |
1 ms |
972 KB |
Output is correct |
19 |
Correct |
1 ms |
684 KB |
Output is correct |
20 |
Correct |
1 ms |
812 KB |
Output is correct |
21 |
Correct |
1 ms |
972 KB |
Output is correct |
22 |
Correct |
1 ms |
588 KB |
Output is correct |
23 |
Correct |
1 ms |
1100 KB |
Output is correct |
24 |
Correct |
1 ms |
844 KB |
Output is correct |
25 |
Correct |
1 ms |
972 KB |
Output is correct |
26 |
Correct |
1 ms |
940 KB |
Output is correct |
27 |
Correct |
1 ms |
560 KB |
Output is correct |
28 |
Correct |
1 ms |
588 KB |
Output is correct |
29 |
Correct |
1 ms |
1100 KB |
Output is correct |
30 |
Correct |
1 ms |
1100 KB |
Output is correct |
31 |
Correct |
1 ms |
972 KB |
Output is correct |
32 |
Correct |
1 ms |
940 KB |
Output is correct |
33 |
Correct |
1 ms |
1100 KB |
Output is correct |
34 |
Correct |
1 ms |
1100 KB |
Output is correct |
35 |
Correct |
1 ms |
1064 KB |
Output is correct |
36 |
Correct |
101 ms |
104916 KB |
Output is correct |
37 |
Correct |
63 ms |
63664 KB |
Output is correct |
38 |
Correct |
28 ms |
33868 KB |
Output is correct |
39 |
Correct |
51 ms |
60100 KB |
Output is correct |
40 |
Correct |
72 ms |
78020 KB |
Output is correct |
41 |
Correct |
26 ms |
28928 KB |
Output is correct |
42 |
Correct |
14 ms |
22604 KB |
Output is correct |
43 |
Correct |
25 ms |
28236 KB |
Output is correct |
44 |
Correct |
6 ms |
10828 KB |
Output is correct |
45 |
Correct |
26 ms |
29516 KB |
Output is correct |
46 |
Correct |
12 ms |
21060 KB |
Output is correct |
47 |
Correct |
24 ms |
30168 KB |
Output is correct |
48 |
Correct |
13 ms |
23664 KB |
Output is correct |
49 |
Correct |
21 ms |
28304 KB |
Output is correct |
50 |
Correct |
10 ms |
14796 KB |
Output is correct |
51 |
Correct |
21 ms |
28236 KB |
Output is correct |
52 |
Correct |
5 ms |
10060 KB |
Output is correct |
53 |
Correct |
17 ms |
27724 KB |
Output is correct |
54 |
Correct |
7 ms |
13200 KB |
Output is correct |
55 |
Correct |
18 ms |
29516 KB |
Output is correct |
56 |
Correct |
10 ms |
16204 KB |
Output is correct |
57 |
Correct |
18 ms |
30716 KB |
Output is correct |
58 |
Correct |
10 ms |
17996 KB |
Output is correct |
59 |
Correct |
160 ms |
129444 KB |
Output is correct |
60 |
Correct |
47 ms |
87116 KB |
Output is correct |
61 |
Correct |
160 ms |
129444 KB |
Output is correct |
62 |
Correct |
45 ms |
86136 KB |
Output is correct |
63 |
Correct |
164 ms |
129444 KB |
Output is correct |
64 |
Correct |
53 ms |
87176 KB |
Output is correct |
65 |
Correct |
117 ms |
116876 KB |
Output is correct |
66 |
Correct |
109 ms |
107272 KB |
Output is correct |
67 |
Correct |
110 ms |
102712 KB |
Output is correct |
68 |
Correct |
91 ms |
94756 KB |
Output is correct |
69 |
Correct |
118 ms |
115648 KB |
Output is correct |
70 |
Correct |
143 ms |
110824 KB |
Output is correct |
71 |
Correct |
96 ms |
112036 KB |
Output is correct |
72 |
Correct |
158 ms |
113164 KB |
Output is correct |
73 |
Correct |
76 ms |
104904 KB |
Output is correct |
74 |
Correct |
129 ms |
98088 KB |
Output is correct |
75 |
Correct |
95 ms |
108436 KB |
Output is correct |
76 |
Correct |
157 ms |
124340 KB |
Output is correct |
77 |
Correct |
111 ms |
124260 KB |
Output is correct |
78 |
Correct |
108 ms |
95860 KB |
Output is correct |
79 |
Correct |
101 ms |
99212 KB |
Output is correct |
80 |
Correct |
150 ms |
121824 KB |
Output is correct |
81 |
Correct |
87 ms |
100352 KB |
Output is correct |
82 |
Correct |
94 ms |
106072 KB |
Output is correct |
83 |
Correct |
121 ms |
129444 KB |
Output is correct |
84 |
Correct |
100 ms |
110824 KB |
Output is correct |
85 |
Correct |
90 ms |
120572 KB |
Output is correct |
86 |
Correct |
111 ms |
118104 KB |
Output is correct |
87 |
Correct |
105 ms |
108448 KB |
Output is correct |
88 |
Correct |
166 ms |
130740 KB |
Output is correct |
89 |
Correct |
159 ms |
130744 KB |
Output is correct |
90 |
Correct |
61 ms |
109632 KB |
Output is correct |
91 |
Correct |
168 ms |
130804 KB |
Output is correct |
92 |
Correct |
173 ms |
130664 KB |
Output is correct |
93 |
Correct |
74 ms |
128068 KB |
Output is correct |