#include <bits/stdc++.h>
using namespace std;
int dp[205][205][205][2], x[205], t[205], n, l;
int d(int i, int j)
{
return min(abs(x[i]-x[j]), l-abs(x[i]-x[j]));
}
int f(int l, int r, int c, int s)
{
if (!c)
return 1e9;
if (c>r-l+1)
return -1e9;
if (dp[l][r][c][s]!=-1e9)
return dp[l][r][c][s];
int ind, ans=-1e9;
if (s)
ind=r+1;
else
ind=l-1;
ans=max(ans, f(l+1, r, c, 0)-d(ind, l));
ans=max(ans, f(l, r-1, c, 1)-d(ind, r));
ans=max(ans, min(f(l+1, r, c-1, 0), t[l])-d(ind, l));
ans=max(ans, min(f(l, r-1, c-1, 1), t[r])-d(ind, r));
dp[l][r][c][s]=ans;
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
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=1; i<=n; i++)
for (int j=i; j<=n; j++)
for (int k=1; k<=j-i+1; k++)
dp[i][j][k][0]=dp[i][j][k][1]=-1e9;
for (int i=1; i<=n; i++)
{
if (f(1, n, i, 0)<0)
{
cout << i-1;
return 0;
}
}
cout << n;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
536 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
0 ms |
468 KB |
Output is correct |
33 |
Correct |
0 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
452 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
60 ms |
26708 KB |
Output is correct |
19 |
Correct |
28 ms |
16340 KB |
Output is correct |
20 |
Correct |
11 ms |
8928 KB |
Output is correct |
21 |
Correct |
26 ms |
15528 KB |
Output is correct |
22 |
Correct |
48 ms |
19996 KB |
Output is correct |
23 |
Correct |
9 ms |
7636 KB |
Output is correct |
24 |
Correct |
6 ms |
5972 KB |
Output is correct |
25 |
Correct |
9 ms |
7380 KB |
Output is correct |
26 |
Correct |
3 ms |
3028 KB |
Output is correct |
27 |
Correct |
9 ms |
7764 KB |
Output is correct |
28 |
Correct |
6 ms |
5664 KB |
Output is correct |
29 |
Correct |
9 ms |
7968 KB |
Output is correct |
30 |
Correct |
6 ms |
6228 KB |
Output is correct |
31 |
Correct |
9 ms |
7364 KB |
Output is correct |
32 |
Correct |
4 ms |
4052 KB |
Output is correct |
33 |
Correct |
8 ms |
7380 KB |
Output is correct |
34 |
Correct |
2 ms |
2772 KB |
Output is correct |
35 |
Correct |
6 ms |
7252 KB |
Output is correct |
36 |
Correct |
3 ms |
3540 KB |
Output is correct |
37 |
Correct |
6 ms |
7748 KB |
Output is correct |
38 |
Correct |
4 ms |
4424 KB |
Output is correct |
39 |
Correct |
7 ms |
8020 KB |
Output is correct |
40 |
Correct |
4 ms |
4820 KB |
Output is correct |
41 |
Correct |
82 ms |
32852 KB |
Output is correct |
42 |
Correct |
11 ms |
22228 KB |
Output is correct |
43 |
Correct |
85 ms |
32852 KB |
Output is correct |
44 |
Correct |
11 ms |
22052 KB |
Output is correct |
45 |
Correct |
84 ms |
32944 KB |
Output is correct |
46 |
Correct |
13 ms |
22228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
328 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
536 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
0 ms |
468 KB |
Output is correct |
33 |
Correct |
0 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
452 KB |
Output is correct |
35 |
Correct |
1 ms |
468 KB |
Output is correct |
36 |
Correct |
60 ms |
26708 KB |
Output is correct |
37 |
Correct |
28 ms |
16340 KB |
Output is correct |
38 |
Correct |
11 ms |
8928 KB |
Output is correct |
39 |
Correct |
26 ms |
15528 KB |
Output is correct |
40 |
Correct |
48 ms |
19996 KB |
Output is correct |
41 |
Correct |
9 ms |
7636 KB |
Output is correct |
42 |
Correct |
6 ms |
5972 KB |
Output is correct |
43 |
Correct |
9 ms |
7380 KB |
Output is correct |
44 |
Correct |
3 ms |
3028 KB |
Output is correct |
45 |
Correct |
9 ms |
7764 KB |
Output is correct |
46 |
Correct |
6 ms |
5664 KB |
Output is correct |
47 |
Correct |
9 ms |
7968 KB |
Output is correct |
48 |
Correct |
6 ms |
6228 KB |
Output is correct |
49 |
Correct |
9 ms |
7364 KB |
Output is correct |
50 |
Correct |
4 ms |
4052 KB |
Output is correct |
51 |
Correct |
8 ms |
7380 KB |
Output is correct |
52 |
Correct |
2 ms |
2772 KB |
Output is correct |
53 |
Correct |
6 ms |
7252 KB |
Output is correct |
54 |
Correct |
3 ms |
3540 KB |
Output is correct |
55 |
Correct |
6 ms |
7748 KB |
Output is correct |
56 |
Correct |
4 ms |
4424 KB |
Output is correct |
57 |
Correct |
7 ms |
8020 KB |
Output is correct |
58 |
Correct |
4 ms |
4820 KB |
Output is correct |
59 |
Correct |
82 ms |
32852 KB |
Output is correct |
60 |
Correct |
11 ms |
22228 KB |
Output is correct |
61 |
Correct |
85 ms |
32852 KB |
Output is correct |
62 |
Correct |
11 ms |
22052 KB |
Output is correct |
63 |
Correct |
84 ms |
32944 KB |
Output is correct |
64 |
Correct |
13 ms |
22228 KB |
Output is correct |
65 |
Correct |
70 ms |
29796 KB |
Output is correct |
66 |
Correct |
62 ms |
27336 KB |
Output is correct |
67 |
Correct |
57 ms |
26164 KB |
Output is correct |
68 |
Correct |
50 ms |
24148 KB |
Output is correct |
69 |
Correct |
70 ms |
29396 KB |
Output is correct |
70 |
Correct |
78 ms |
28280 KB |
Output is correct |
71 |
Correct |
64 ms |
28584 KB |
Output is correct |
72 |
Correct |
70 ms |
28884 KB |
Output is correct |
73 |
Correct |
58 ms |
26792 KB |
Output is correct |
74 |
Correct |
57 ms |
25088 KB |
Output is correct |
75 |
Correct |
62 ms |
27604 KB |
Output is correct |
76 |
Correct |
79 ms |
31664 KB |
Output is correct |
77 |
Correct |
83 ms |
31672 KB |
Output is correct |
78 |
Correct |
57 ms |
24500 KB |
Output is correct |
79 |
Correct |
55 ms |
25368 KB |
Output is correct |
80 |
Correct |
78 ms |
31040 KB |
Output is correct |
81 |
Correct |
55 ms |
25556 KB |
Output is correct |
82 |
Correct |
50 ms |
27092 KB |
Output is correct |
83 |
Correct |
80 ms |
32852 KB |
Output is correct |
84 |
Correct |
56 ms |
28276 KB |
Output is correct |
85 |
Correct |
73 ms |
30724 KB |
Output is correct |
86 |
Correct |
60 ms |
30104 KB |
Output is correct |
87 |
Correct |
62 ms |
27688 KB |
Output is correct |
88 |
Correct |
85 ms |
33276 KB |
Output is correct |
89 |
Correct |
86 ms |
33224 KB |
Output is correct |
90 |
Correct |
14 ms |
27984 KB |
Output is correct |
91 |
Correct |
88 ms |
33236 KB |
Output is correct |
92 |
Correct |
85 ms |
33180 KB |
Output is correct |
93 |
Correct |
16 ms |
32596 KB |
Output is correct |