#include<bits/stdc++.h>
#define ll int
#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 ll INF=1000000005;
ll n, L, a[205], t[205], res;
ll dp[205][205][205][2];
bool check[205][205][205][2];
ll dis(ll l, ll r, ll 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];
}
ll calc(ll l, ll r, ll k, ll di)
{
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];
ll ans=INF;
if (!di)
{
ll A=calc((l+1)%n, r, k-1, 0);
ll B=calc((l+1)%n, r, k, 0);
ll C=calc((l+1)%n, r, k-1, 1);
ll D=calc((l+1)%n, r, k, 1);
ll 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
{
ll A=calc(l, (r-1+n)%n, k-1, 0);
ll B=calc(l, (r-1+n)%n, k, 0);
ll C=calc(l, (r-1+n)%n, k-1, 1);
ll D=calc(l, (r-1+n)%n, k, 1);
ll 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 (ll i=0; i<n; i++)
cin >> a[i];
for (ll i=0; i<n; i++)
cin >> t[i];
for (ll i=0; i<n; i++)
for (ll j=0; j<n; j++)
for (ll k=0; k<=n; k++)
for (ll 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 (ll i=0; i<n; i++)
for (ll j=0; j<n; j++)
for (ll 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 |
0 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 |
0 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 |
1 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 |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 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 |
0 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 |
0 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 |
1 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 |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 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 |
0 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 |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
852 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 |
0 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 |
0 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 |
1 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 |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 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 |
462 ms |
65976 KB |
Output is correct |
19 |
Correct |
236 ms |
40168 KB |
Output is correct |
20 |
Correct |
83 ms |
21452 KB |
Output is correct |
21 |
Correct |
197 ms |
37896 KB |
Output is correct |
22 |
Correct |
288 ms |
49012 KB |
Output is correct |
23 |
Correct |
67 ms |
18256 KB |
Output is correct |
24 |
Correct |
47 ms |
14308 KB |
Output is correct |
25 |
Correct |
65 ms |
17868 KB |
Output is correct |
26 |
Correct |
18 ms |
6920 KB |
Output is correct |
27 |
Correct |
68 ms |
18596 KB |
Output is correct |
28 |
Correct |
41 ms |
13284 KB |
Output is correct |
29 |
Correct |
71 ms |
19012 KB |
Output is correct |
30 |
Correct |
51 ms |
15120 KB |
Output is correct |
31 |
Correct |
67 ms |
17892 KB |
Output is correct |
32 |
Correct |
25 ms |
9428 KB |
Output is correct |
33 |
Correct |
66 ms |
17868 KB |
Output is correct |
34 |
Correct |
16 ms |
6484 KB |
Output is correct |
35 |
Correct |
63 ms |
17564 KB |
Output is correct |
36 |
Correct |
21 ms |
8380 KB |
Output is correct |
37 |
Correct |
69 ms |
18640 KB |
Output is correct |
38 |
Correct |
31 ms |
10312 KB |
Output is correct |
39 |
Correct |
76 ms |
19432 KB |
Output is correct |
40 |
Correct |
33 ms |
11480 KB |
Output is correct |
41 |
Correct |
608 ms |
81148 KB |
Output is correct |
42 |
Correct |
342 ms |
54896 KB |
Output is correct |
43 |
Correct |
619 ms |
81056 KB |
Output is correct |
44 |
Correct |
336 ms |
54136 KB |
Output is correct |
45 |
Correct |
618 ms |
81096 KB |
Output is correct |
46 |
Correct |
337 ms |
54804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 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 |
1 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 |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 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 |
0 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 |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
852 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 |
462 ms |
65976 KB |
Output is correct |
37 |
Correct |
236 ms |
40168 KB |
Output is correct |
38 |
Correct |
83 ms |
21452 KB |
Output is correct |
39 |
Correct |
197 ms |
37896 KB |
Output is correct |
40 |
Correct |
288 ms |
49012 KB |
Output is correct |
41 |
Correct |
67 ms |
18256 KB |
Output is correct |
42 |
Correct |
47 ms |
14308 KB |
Output is correct |
43 |
Correct |
65 ms |
17868 KB |
Output is correct |
44 |
Correct |
18 ms |
6920 KB |
Output is correct |
45 |
Correct |
68 ms |
18596 KB |
Output is correct |
46 |
Correct |
41 ms |
13284 KB |
Output is correct |
47 |
Correct |
71 ms |
19012 KB |
Output is correct |
48 |
Correct |
51 ms |
15120 KB |
Output is correct |
49 |
Correct |
67 ms |
17892 KB |
Output is correct |
50 |
Correct |
25 ms |
9428 KB |
Output is correct |
51 |
Correct |
66 ms |
17868 KB |
Output is correct |
52 |
Correct |
16 ms |
6484 KB |
Output is correct |
53 |
Correct |
63 ms |
17564 KB |
Output is correct |
54 |
Correct |
21 ms |
8380 KB |
Output is correct |
55 |
Correct |
69 ms |
18640 KB |
Output is correct |
56 |
Correct |
31 ms |
10312 KB |
Output is correct |
57 |
Correct |
76 ms |
19432 KB |
Output is correct |
58 |
Correct |
33 ms |
11480 KB |
Output is correct |
59 |
Correct |
608 ms |
81148 KB |
Output is correct |
60 |
Correct |
342 ms |
54896 KB |
Output is correct |
61 |
Correct |
619 ms |
81056 KB |
Output is correct |
62 |
Correct |
336 ms |
54136 KB |
Output is correct |
63 |
Correct |
618 ms |
81096 KB |
Output is correct |
64 |
Correct |
337 ms |
54804 KB |
Output is correct |
65 |
Correct |
539 ms |
73328 KB |
Output is correct |
66 |
Correct |
465 ms |
67360 KB |
Output is correct |
67 |
Correct |
435 ms |
64508 KB |
Output is correct |
68 |
Correct |
389 ms |
59640 KB |
Output is correct |
69 |
Correct |
515 ms |
72676 KB |
Output is correct |
70 |
Correct |
490 ms |
69776 KB |
Output is correct |
71 |
Correct |
498 ms |
70308 KB |
Output is correct |
72 |
Correct |
507 ms |
71252 KB |
Output is correct |
73 |
Correct |
447 ms |
65868 KB |
Output is correct |
74 |
Correct |
398 ms |
61584 KB |
Output is correct |
75 |
Correct |
470 ms |
68260 KB |
Output is correct |
76 |
Correct |
573 ms |
78072 KB |
Output is correct |
77 |
Correct |
586 ms |
78048 KB |
Output is correct |
78 |
Correct |
389 ms |
60344 KB |
Output is correct |
79 |
Correct |
403 ms |
62412 KB |
Output is correct |
80 |
Correct |
561 ms |
76512 KB |
Output is correct |
81 |
Correct |
419 ms |
63020 KB |
Output is correct |
82 |
Correct |
457 ms |
66712 KB |
Output is correct |
83 |
Correct |
605 ms |
80916 KB |
Output is correct |
84 |
Correct |
480 ms |
69692 KB |
Output is correct |
85 |
Correct |
570 ms |
75808 KB |
Output is correct |
86 |
Correct |
539 ms |
74264 KB |
Output is correct |
87 |
Correct |
479 ms |
68124 KB |
Output is correct |
88 |
Correct |
648 ms |
81740 KB |
Output is correct |
89 |
Correct |
634 ms |
81652 KB |
Output is correct |
90 |
Correct |
482 ms |
68844 KB |
Output is correct |
91 |
Correct |
635 ms |
81812 KB |
Output is correct |
92 |
Correct |
671 ms |
81736 KB |
Output is correct |
93 |
Correct |
597 ms |
80400 KB |
Output is correct |