#include <bits/stdc++.h>
using namespace std;
const int N = 2e2 + 10;
int n, l, pos[N], t[N], ans;
long long dp[N][N][N][2];
long long d( int a, int b ) { return min( abs( pos[b] - pos[a] ), l - abs( pos[b] - pos[a] ) ); }
int main()
{
scanf("%d %d",&n,&l);
for( int i = 1 ; i <= n ; i++ ) scanf("%d",&pos[i]);
for( int i = 1 ; i <= n ; i++ ) scanf("%d",&t[i]);
pos[n+1] = l;
for( int k = 0 ; k <= n ; k++ ) for( int i = 0 ; i <= n ; i++ ) for( int j = n+1 ; j >= 1 ; j-- ) {
if( j <= i || ( !k && !i && j == n+1 ) ) continue;
dp[i][j][k][0] = dp[i][j][k][1] = 1e18;
if( i ) dp[i][j][k][0] = min( dp[i][j][k][0], min( dp[i-1][j][k][0] + d( i-1, i ), dp[i-1][j][k][1] + d( j, i ) ) );
if( j != n+1 ) dp[i][j][k][1] = min( dp[i][j][k][1], min( dp[i][j+1][k][0] + d( i, j ), dp[i][j+1][k][1] + d( j+1, j ) ) );
if( k ) {
if( i ) {
long long T = min( dp[i-1][j][k-1][0] + d( i-1, i ), dp[i-1][j][k-1][1] + d( j, i ) );
if( T <= t[i] ) dp[i][j][k][0] = min( dp[i][j][k][0], T );
}
if( j <= n ) {
long long T = min( dp[i][j+1][k-1][0] + d( i, j ), dp[i][j+1][k-1][1] + d( j+1, j ) );
if( T <= t[j] ) dp[i][j][k][1] = min( dp[i][j][k][1], T );
}
}
if( dp[i][j][k][0] != 1e18 || dp[i][j][k][1] != 1e18 ) ans = k;
}
printf("%d",ans);
return 0;
}
Compilation message
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n,&l);
~~~~~^~~~~~~~~~~~~~~
ho_t3.cpp:13:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for( int i = 1 ; i <= n ; i++ ) scanf("%d",&pos[i]);
~~~~~^~~~~~~~~~~~~~
ho_t3.cpp:14:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for( int i = 1 ; i <= n ; i++ ) scanf("%d",&t[i]);
~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
688 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
21 |
Correct |
6 ms |
768 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
768 KB |
Output is correct |
24 |
Correct |
5 ms |
640 KB |
Output is correct |
25 |
Correct |
5 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
768 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
768 KB |
Output is correct |
30 |
Correct |
5 ms |
896 KB |
Output is correct |
31 |
Correct |
5 ms |
768 KB |
Output is correct |
32 |
Correct |
5 ms |
640 KB |
Output is correct |
33 |
Correct |
4 ms |
768 KB |
Output is correct |
34 |
Correct |
5 ms |
896 KB |
Output is correct |
35 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
688 KB |
Output is correct |
18 |
Correct |
103 ms |
54648 KB |
Output is correct |
19 |
Correct |
55 ms |
33272 KB |
Output is correct |
20 |
Correct |
27 ms |
17920 KB |
Output is correct |
21 |
Correct |
53 ms |
31480 KB |
Output is correct |
22 |
Correct |
78 ms |
40880 KB |
Output is correct |
23 |
Correct |
23 ms |
15360 KB |
Output is correct |
24 |
Correct |
18 ms |
12032 KB |
Output is correct |
25 |
Correct |
23 ms |
14976 KB |
Output is correct |
26 |
Correct |
9 ms |
5888 KB |
Output is correct |
27 |
Correct |
24 ms |
15616 KB |
Output is correct |
28 |
Correct |
16 ms |
11264 KB |
Output is correct |
29 |
Correct |
25 ms |
16000 KB |
Output is correct |
30 |
Correct |
19 ms |
12672 KB |
Output is correct |
31 |
Correct |
23 ms |
14976 KB |
Output is correct |
32 |
Correct |
13 ms |
8064 KB |
Output is correct |
33 |
Correct |
24 ms |
14976 KB |
Output is correct |
34 |
Correct |
9 ms |
5504 KB |
Output is correct |
35 |
Correct |
21 ms |
14720 KB |
Output is correct |
36 |
Correct |
11 ms |
7168 KB |
Output is correct |
37 |
Correct |
23 ms |
15616 KB |
Output is correct |
38 |
Correct |
13 ms |
8704 KB |
Output is correct |
39 |
Correct |
24 ms |
16256 KB |
Output is correct |
40 |
Correct |
14 ms |
9728 KB |
Output is correct |
41 |
Correct |
137 ms |
67320 KB |
Output is correct |
42 |
Correct |
84 ms |
45432 KB |
Output is correct |
43 |
Correct |
146 ms |
67320 KB |
Output is correct |
44 |
Correct |
84 ms |
44920 KB |
Output is correct |
45 |
Correct |
140 ms |
67320 KB |
Output is correct |
46 |
Correct |
81 ms |
45560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
640 KB |
Output is correct |
7 |
Correct |
5 ms |
512 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
5 ms |
640 KB |
Output is correct |
14 |
Correct |
5 ms |
512 KB |
Output is correct |
15 |
Correct |
5 ms |
512 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
688 KB |
Output is correct |
18 |
Correct |
5 ms |
768 KB |
Output is correct |
19 |
Correct |
5 ms |
512 KB |
Output is correct |
20 |
Correct |
5 ms |
640 KB |
Output is correct |
21 |
Correct |
6 ms |
768 KB |
Output is correct |
22 |
Correct |
5 ms |
512 KB |
Output is correct |
23 |
Correct |
5 ms |
768 KB |
Output is correct |
24 |
Correct |
5 ms |
640 KB |
Output is correct |
25 |
Correct |
5 ms |
768 KB |
Output is correct |
26 |
Correct |
5 ms |
768 KB |
Output is correct |
27 |
Correct |
5 ms |
512 KB |
Output is correct |
28 |
Correct |
5 ms |
512 KB |
Output is correct |
29 |
Correct |
5 ms |
768 KB |
Output is correct |
30 |
Correct |
5 ms |
896 KB |
Output is correct |
31 |
Correct |
5 ms |
768 KB |
Output is correct |
32 |
Correct |
5 ms |
640 KB |
Output is correct |
33 |
Correct |
4 ms |
768 KB |
Output is correct |
34 |
Correct |
5 ms |
896 KB |
Output is correct |
35 |
Correct |
5 ms |
896 KB |
Output is correct |
36 |
Correct |
103 ms |
54648 KB |
Output is correct |
37 |
Correct |
55 ms |
33272 KB |
Output is correct |
38 |
Correct |
27 ms |
17920 KB |
Output is correct |
39 |
Correct |
53 ms |
31480 KB |
Output is correct |
40 |
Correct |
78 ms |
40880 KB |
Output is correct |
41 |
Correct |
23 ms |
15360 KB |
Output is correct |
42 |
Correct |
18 ms |
12032 KB |
Output is correct |
43 |
Correct |
23 ms |
14976 KB |
Output is correct |
44 |
Correct |
9 ms |
5888 KB |
Output is correct |
45 |
Correct |
24 ms |
15616 KB |
Output is correct |
46 |
Correct |
16 ms |
11264 KB |
Output is correct |
47 |
Correct |
25 ms |
16000 KB |
Output is correct |
48 |
Correct |
19 ms |
12672 KB |
Output is correct |
49 |
Correct |
23 ms |
14976 KB |
Output is correct |
50 |
Correct |
13 ms |
8064 KB |
Output is correct |
51 |
Correct |
24 ms |
14976 KB |
Output is correct |
52 |
Correct |
9 ms |
5504 KB |
Output is correct |
53 |
Correct |
21 ms |
14720 KB |
Output is correct |
54 |
Correct |
11 ms |
7168 KB |
Output is correct |
55 |
Correct |
23 ms |
15616 KB |
Output is correct |
56 |
Correct |
13 ms |
8704 KB |
Output is correct |
57 |
Correct |
24 ms |
16256 KB |
Output is correct |
58 |
Correct |
14 ms |
9728 KB |
Output is correct |
59 |
Correct |
137 ms |
67320 KB |
Output is correct |
60 |
Correct |
84 ms |
45432 KB |
Output is correct |
61 |
Correct |
146 ms |
67320 KB |
Output is correct |
62 |
Correct |
84 ms |
44920 KB |
Output is correct |
63 |
Correct |
140 ms |
67320 KB |
Output is correct |
64 |
Correct |
81 ms |
45560 KB |
Output is correct |
65 |
Correct |
121 ms |
60792 KB |
Output is correct |
66 |
Correct |
125 ms |
55800 KB |
Output is correct |
67 |
Correct |
104 ms |
53496 KB |
Output is correct |
68 |
Correct |
91 ms |
49400 KB |
Output is correct |
69 |
Correct |
157 ms |
60152 KB |
Output is correct |
70 |
Correct |
116 ms |
57720 KB |
Output is correct |
71 |
Correct |
112 ms |
58236 KB |
Output is correct |
72 |
Correct |
122 ms |
58872 KB |
Output is correct |
73 |
Correct |
104 ms |
54648 KB |
Output is correct |
74 |
Correct |
100 ms |
51064 KB |
Output is correct |
75 |
Correct |
118 ms |
56440 KB |
Output is correct |
76 |
Correct |
132 ms |
64632 KB |
Output is correct |
77 |
Correct |
126 ms |
64632 KB |
Output is correct |
78 |
Correct |
100 ms |
49912 KB |
Output is correct |
79 |
Correct |
108 ms |
51708 KB |
Output is correct |
80 |
Correct |
139 ms |
63352 KB |
Output is correct |
81 |
Correct |
97 ms |
52216 KB |
Output is correct |
82 |
Correct |
107 ms |
55288 KB |
Output is correct |
83 |
Correct |
134 ms |
67320 KB |
Output is correct |
84 |
Correct |
111 ms |
57720 KB |
Output is correct |
85 |
Correct |
128 ms |
62712 KB |
Output is correct |
86 |
Correct |
123 ms |
61432 KB |
Output is correct |
87 |
Correct |
110 ms |
56388 KB |
Output is correct |
88 |
Correct |
150 ms |
68112 KB |
Output is correct |
89 |
Correct |
141 ms |
67964 KB |
Output is correct |
90 |
Correct |
110 ms |
57080 KB |
Output is correct |
91 |
Correct |
142 ms |
68020 KB |
Output is correct |
92 |
Correct |
140 ms |
67960 KB |
Output is correct |
93 |
Correct |
138 ms |
66680 KB |
Output is correct |