#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
#define LOCALIO "C:/Users/admin/Documents/Code/"
const int INF=1000000005;
int n, L, a[205], t[205], res;
int dp[205][205][205][2];
bool check[205][205][205][2];
int dis(int l, int r, int di)
{
if (!di)
{
if (r<l)
return a[r]-a[l]+L;
return a[r]-a[l];
}
if (r>l)
return a[l]-a[r]+L;
return a[l]-a[r];
}
bool test(ll l, ll r)
{
if (l>r) l-=n;
if (l<=0 && r>=0)
return 1;
if (l<=n-1 && r>=n-1)
return 1;
return 0;
}
int calc(int l, int r, int k, int di)
{
if (!test(l, r))
return INF;
if (k<0) return INF;
if (check[l][r][k][di])
return dp[l][r][k][di];
if (l==r)
return dp[l][r][k][di];
int ans=INF;
if (!di)
{
int A=calc((l+1)%n, r, k-1, 0);
int B=calc((l+1)%n, r, k, 0);
int C=calc((l+1)%n, r, k-1, 1);
int D=calc((l+1)%n, r, k, 1);
int dis1=dis((l+1)%n, l, 1), dis2=dis(r, l, 1);
if (t[l]>=A+dis1)
ans=min(ans, A+dis1);
ans=min(ans, B+dis1);
if (t[l]>=C+dis2)
ans=min(ans, C+dis2);
ans=min(ans, D+dis2);
}
else
{
int A=calc(l, (r-1+n)%n, k-1, 0);
int B=calc(l, (r-1+n)%n, k, 0);
int C=calc(l, (r-1+n)%n, k-1, 1);
int D=calc(l, (r-1+n)%n, k, 1);
int dis1=dis((r-1+n)%n, r, 0), dis2=dis(l, r, 0);
if (t[r]>=A+dis2)
ans=min(ans, A+dis2);
ans=min(ans, B+dis2);
if (t[r]>=C+dis1)
ans=min(ans, C+dis1);
ans=min(ans, D+dis1);
}
dp[l][r][k][di]=ans;
check[l][r][k][di]=1;
if (l==(r+1)%n && ans!=INF)
res=max(res, k);
return ans;
}
int main()
{
#ifdef LOCAL
freopen( LOCALIO "input.txt","r",stdin) ;
freopen( LOCALIO "output.txt","w",stdout) ;
#endif
ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
// freopen("FIBONACCI.inp","r",stdin);
// freopen("FIBONACCI.out","w",stdout);
cin >> n >> L;
for (int i=0; i<n; i++)
cin >> a[i];
for (int i=0; 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; k++)
for (int di=0; di<2; di++)
dp[i][j][k][di]=INF;
if (t[0]>=a[0] || t[n-1]>=L-a[n-1])
res=1;
dp[0][0][t[0]>=a[0]][0]=a[0];
dp[0][0][0][0]=a[0];
dp[n-1][n-1][t[n-1]>=L-a[n-1]][0]=L-a[n-1];
dp[n-1][n-1][0][0]=L-a[n-1];
for (int i=0; i<n; i++)
for (int j=0; j<n; j++)
for (int k=0; k<=n; k++)
calc(i, j, k, 0), calc(i, j, k, 1);
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
852 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
0 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
876 KB |
Output is correct |
30 |
Correct |
1 ms |
852 KB |
Output is correct |
31 |
Correct |
1 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
724 KB |
Output is correct |
33 |
Correct |
1 ms |
852 KB |
Output is correct |
34 |
Correct |
1 ms |
852 KB |
Output is correct |
35 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
280 ms |
60308 KB |
Output is correct |
19 |
Correct |
126 ms |
36848 KB |
Output is correct |
20 |
Correct |
55 ms |
19840 KB |
Output is correct |
21 |
Correct |
118 ms |
34744 KB |
Output is correct |
22 |
Correct |
194 ms |
44960 KB |
Output is correct |
23 |
Correct |
47 ms |
16972 KB |
Output is correct |
24 |
Correct |
34 ms |
13364 KB |
Output is correct |
25 |
Correct |
39 ms |
16560 KB |
Output is correct |
26 |
Correct |
10 ms |
6484 KB |
Output is correct |
27 |
Correct |
42 ms |
17228 KB |
Output is correct |
28 |
Correct |
26 ms |
12384 KB |
Output is correct |
29 |
Correct |
44 ms |
17612 KB |
Output is correct |
30 |
Correct |
31 ms |
13976 KB |
Output is correct |
31 |
Correct |
47 ms |
16612 KB |
Output is correct |
32 |
Correct |
22 ms |
8852 KB |
Output is correct |
33 |
Correct |
44 ms |
16588 KB |
Output is correct |
34 |
Correct |
9 ms |
6100 KB |
Output is correct |
35 |
Correct |
40 ms |
16284 KB |
Output is correct |
36 |
Correct |
14 ms |
7840 KB |
Output is correct |
37 |
Correct |
45 ms |
17236 KB |
Output is correct |
38 |
Correct |
19 ms |
9684 KB |
Output is correct |
39 |
Correct |
48 ms |
18040 KB |
Output is correct |
40 |
Correct |
22 ms |
10744 KB |
Output is correct |
41 |
Correct |
433 ms |
74032 KB |
Output is correct |
42 |
Correct |
204 ms |
50184 KB |
Output is correct |
43 |
Correct |
370 ms |
73968 KB |
Output is correct |
44 |
Correct |
202 ms |
49764 KB |
Output is correct |
45 |
Correct |
362 ms |
73884 KB |
Output is correct |
46 |
Correct |
214 ms |
50212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
0 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
1 ms |
596 KB |
Output is correct |
18 |
Correct |
1 ms |
724 KB |
Output is correct |
19 |
Correct |
1 ms |
596 KB |
Output is correct |
20 |
Correct |
1 ms |
596 KB |
Output is correct |
21 |
Correct |
1 ms |
724 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
852 KB |
Output is correct |
24 |
Correct |
1 ms |
724 KB |
Output is correct |
25 |
Correct |
1 ms |
724 KB |
Output is correct |
26 |
Correct |
1 ms |
724 KB |
Output is correct |
27 |
Correct |
0 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
876 KB |
Output is correct |
30 |
Correct |
1 ms |
852 KB |
Output is correct |
31 |
Correct |
1 ms |
724 KB |
Output is correct |
32 |
Correct |
1 ms |
724 KB |
Output is correct |
33 |
Correct |
1 ms |
852 KB |
Output is correct |
34 |
Correct |
1 ms |
852 KB |
Output is correct |
35 |
Correct |
1 ms |
852 KB |
Output is correct |
36 |
Correct |
280 ms |
60308 KB |
Output is correct |
37 |
Correct |
126 ms |
36848 KB |
Output is correct |
38 |
Correct |
55 ms |
19840 KB |
Output is correct |
39 |
Correct |
118 ms |
34744 KB |
Output is correct |
40 |
Correct |
194 ms |
44960 KB |
Output is correct |
41 |
Correct |
47 ms |
16972 KB |
Output is correct |
42 |
Correct |
34 ms |
13364 KB |
Output is correct |
43 |
Correct |
39 ms |
16560 KB |
Output is correct |
44 |
Correct |
10 ms |
6484 KB |
Output is correct |
45 |
Correct |
42 ms |
17228 KB |
Output is correct |
46 |
Correct |
26 ms |
12384 KB |
Output is correct |
47 |
Correct |
44 ms |
17612 KB |
Output is correct |
48 |
Correct |
31 ms |
13976 KB |
Output is correct |
49 |
Correct |
47 ms |
16612 KB |
Output is correct |
50 |
Correct |
22 ms |
8852 KB |
Output is correct |
51 |
Correct |
44 ms |
16588 KB |
Output is correct |
52 |
Correct |
9 ms |
6100 KB |
Output is correct |
53 |
Correct |
40 ms |
16284 KB |
Output is correct |
54 |
Correct |
14 ms |
7840 KB |
Output is correct |
55 |
Correct |
45 ms |
17236 KB |
Output is correct |
56 |
Correct |
19 ms |
9684 KB |
Output is correct |
57 |
Correct |
48 ms |
18040 KB |
Output is correct |
58 |
Correct |
22 ms |
10744 KB |
Output is correct |
59 |
Correct |
433 ms |
74032 KB |
Output is correct |
60 |
Correct |
204 ms |
50184 KB |
Output is correct |
61 |
Correct |
370 ms |
73968 KB |
Output is correct |
62 |
Correct |
202 ms |
49764 KB |
Output is correct |
63 |
Correct |
362 ms |
73884 KB |
Output is correct |
64 |
Correct |
214 ms |
50212 KB |
Output is correct |
65 |
Correct |
342 ms |
67152 KB |
Output is correct |
66 |
Correct |
283 ms |
61628 KB |
Output is correct |
67 |
Correct |
287 ms |
59028 KB |
Output is correct |
68 |
Correct |
233 ms |
54508 KB |
Output is correct |
69 |
Correct |
309 ms |
66480 KB |
Output is correct |
70 |
Correct |
332 ms |
63660 KB |
Output is correct |
71 |
Correct |
288 ms |
64332 KB |
Output is correct |
72 |
Correct |
315 ms |
65036 KB |
Output is correct |
73 |
Correct |
286 ms |
60364 KB |
Output is correct |
74 |
Correct |
242 ms |
56468 KB |
Output is correct |
75 |
Correct |
280 ms |
62296 KB |
Output is correct |
76 |
Correct |
349 ms |
71364 KB |
Output is correct |
77 |
Correct |
353 ms |
71452 KB |
Output is correct |
78 |
Correct |
260 ms |
55132 KB |
Output is correct |
79 |
Correct |
245 ms |
57012 KB |
Output is correct |
80 |
Correct |
350 ms |
69976 KB |
Output is correct |
81 |
Correct |
244 ms |
57704 KB |
Output is correct |
82 |
Correct |
271 ms |
61040 KB |
Output is correct |
83 |
Correct |
368 ms |
73892 KB |
Output is correct |
84 |
Correct |
296 ms |
63848 KB |
Output is correct |
85 |
Correct |
317 ms |
69196 KB |
Output is correct |
86 |
Correct |
320 ms |
67784 KB |
Output is correct |
87 |
Correct |
302 ms |
62412 KB |
Output is correct |
88 |
Correct |
374 ms |
74572 KB |
Output is correct |
89 |
Correct |
369 ms |
74600 KB |
Output is correct |
90 |
Correct |
281 ms |
62944 KB |
Output is correct |
91 |
Correct |
366 ms |
74572 KB |
Output is correct |
92 |
Correct |
374 ms |
74564 KB |
Output is correct |
93 |
Correct |
358 ms |
73240 KB |
Output is correct |