#include <iostream>
using namespace std;
#define MAXN 210
int n;
long long l;
long long dist[MAXN];
long long tm[MAXN];
long long dp[MAXN][MAXN][2][MAXN];
int o = 0;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> l;
for (int i=1; i<=n; i++) {
cin >> dist[i];
}
dist[n+1] = l;
for (int i=1; i<=n; i++) {
cin >> tm[i];
}
for (int i=0; i<=n+1; i++) {
for (int j=0; j<=n+1; j++) {
for (int k=0; k<=n+1; k++) {
dp[i][j][0][k] = dp[i][j][1][k] = 1e16;
}
}
}
dp[0][n+1][0][0] = dp[0][n+1][1][0] = 0;
for (int i=0; i<n; i++) {
for (int j=n+1; j>i+1; j--) {
for (int k=0; k<=n; k++) {
long long d1 = min(dp[i][j][0][k]+dist[i+1]-dist[i], dp[i][j][1][k]+dist[i+1]+l-dist[j]);
dp[i+1][j][0][k+(d1<=tm[i+1])] = min(dp[i+1][j][0][k+(d1<=tm[i+1])], d1);
long long d2 = min(dp[i][j][1][k]+dist[j]-dist[j-1], dp[i][j][0][k]+dist[i]+l-dist[j-1]);
dp[i][j-1][1][k+(d2<=tm[j-1])] = min(dp[i][j-1][1][k+(d2<=tm[j-1])], d2);
}
}
}
for (int i=0; i<=n+1; i++) {
for (int j=0; j<=n+1; j++) {
for (int k=0; k<=n; k++) {
if (dp[i][j][0][k] < 1e16 || dp[i][j][1][k] < 1e16) {
o = max(o, k);
}
}
}
}
cout << o << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Correct |
1 ms |
1024 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Correct |
1 ms |
1024 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
1024 KB |
Output is correct |
18 |
Correct |
1 ms |
1280 KB |
Output is correct |
19 |
Correct |
1 ms |
896 KB |
Output is correct |
20 |
Correct |
0 ms |
1024 KB |
Output is correct |
21 |
Correct |
1 ms |
1280 KB |
Output is correct |
22 |
Correct |
1 ms |
768 KB |
Output is correct |
23 |
Correct |
1 ms |
1280 KB |
Output is correct |
24 |
Correct |
1 ms |
1152 KB |
Output is correct |
25 |
Correct |
1 ms |
1280 KB |
Output is correct |
26 |
Correct |
1 ms |
1280 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
1 ms |
1280 KB |
Output is correct |
30 |
Correct |
1 ms |
1280 KB |
Output is correct |
31 |
Correct |
1 ms |
1280 KB |
Output is correct |
32 |
Correct |
1 ms |
1152 KB |
Output is correct |
33 |
Correct |
1 ms |
1280 KB |
Output is correct |
34 |
Correct |
1 ms |
1280 KB |
Output is correct |
35 |
Correct |
1 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Correct |
1 ms |
1024 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
1024 KB |
Output is correct |
18 |
Correct |
122 ms |
108800 KB |
Output is correct |
19 |
Correct |
71 ms |
66168 KB |
Output is correct |
20 |
Correct |
33 ms |
35584 KB |
Output is correct |
21 |
Correct |
64 ms |
62584 KB |
Output is correct |
22 |
Correct |
86 ms |
80888 KB |
Output is correct |
23 |
Correct |
27 ms |
30336 KB |
Output is correct |
24 |
Correct |
21 ms |
23808 KB |
Output is correct |
25 |
Correct |
27 ms |
29696 KB |
Output is correct |
26 |
Correct |
9 ms |
11648 KB |
Output is correct |
27 |
Correct |
28 ms |
30976 KB |
Output is correct |
28 |
Correct |
20 ms |
22144 KB |
Output is correct |
29 |
Correct |
29 ms |
31616 KB |
Output is correct |
30 |
Correct |
23 ms |
24960 KB |
Output is correct |
31 |
Correct |
27 ms |
29696 KB |
Output is correct |
32 |
Correct |
13 ms |
15744 KB |
Output is correct |
33 |
Correct |
27 ms |
29696 KB |
Output is correct |
34 |
Correct |
8 ms |
10912 KB |
Output is correct |
35 |
Correct |
26 ms |
29184 KB |
Output is correct |
36 |
Correct |
12 ms |
14080 KB |
Output is correct |
37 |
Correct |
28 ms |
30976 KB |
Output is correct |
38 |
Correct |
14 ms |
17152 KB |
Output is correct |
39 |
Correct |
30 ms |
32256 KB |
Output is correct |
40 |
Correct |
17 ms |
19072 KB |
Output is correct |
41 |
Correct |
160 ms |
134008 KB |
Output is correct |
42 |
Correct |
101 ms |
90488 KB |
Output is correct |
43 |
Correct |
166 ms |
134120 KB |
Output is correct |
44 |
Correct |
108 ms |
89464 KB |
Output is correct |
45 |
Correct |
160 ms |
134008 KB |
Output is correct |
46 |
Correct |
99 ms |
90540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
0 ms |
512 KB |
Output is correct |
5 |
Correct |
0 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Correct |
1 ms |
1024 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
1024 KB |
Output is correct |
18 |
Correct |
1 ms |
1280 KB |
Output is correct |
19 |
Correct |
1 ms |
896 KB |
Output is correct |
20 |
Correct |
0 ms |
1024 KB |
Output is correct |
21 |
Correct |
1 ms |
1280 KB |
Output is correct |
22 |
Correct |
1 ms |
768 KB |
Output is correct |
23 |
Correct |
1 ms |
1280 KB |
Output is correct |
24 |
Correct |
1 ms |
1152 KB |
Output is correct |
25 |
Correct |
1 ms |
1280 KB |
Output is correct |
26 |
Correct |
1 ms |
1280 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
1 ms |
1280 KB |
Output is correct |
30 |
Correct |
1 ms |
1280 KB |
Output is correct |
31 |
Correct |
1 ms |
1280 KB |
Output is correct |
32 |
Correct |
1 ms |
1152 KB |
Output is correct |
33 |
Correct |
1 ms |
1280 KB |
Output is correct |
34 |
Correct |
1 ms |
1280 KB |
Output is correct |
35 |
Correct |
1 ms |
1408 KB |
Output is correct |
36 |
Correct |
122 ms |
108800 KB |
Output is correct |
37 |
Correct |
71 ms |
66168 KB |
Output is correct |
38 |
Correct |
33 ms |
35584 KB |
Output is correct |
39 |
Correct |
64 ms |
62584 KB |
Output is correct |
40 |
Correct |
86 ms |
80888 KB |
Output is correct |
41 |
Correct |
27 ms |
30336 KB |
Output is correct |
42 |
Correct |
21 ms |
23808 KB |
Output is correct |
43 |
Correct |
27 ms |
29696 KB |
Output is correct |
44 |
Correct |
9 ms |
11648 KB |
Output is correct |
45 |
Correct |
28 ms |
30976 KB |
Output is correct |
46 |
Correct |
20 ms |
22144 KB |
Output is correct |
47 |
Correct |
29 ms |
31616 KB |
Output is correct |
48 |
Correct |
23 ms |
24960 KB |
Output is correct |
49 |
Correct |
27 ms |
29696 KB |
Output is correct |
50 |
Correct |
13 ms |
15744 KB |
Output is correct |
51 |
Correct |
27 ms |
29696 KB |
Output is correct |
52 |
Correct |
8 ms |
10912 KB |
Output is correct |
53 |
Correct |
26 ms |
29184 KB |
Output is correct |
54 |
Correct |
12 ms |
14080 KB |
Output is correct |
55 |
Correct |
28 ms |
30976 KB |
Output is correct |
56 |
Correct |
14 ms |
17152 KB |
Output is correct |
57 |
Correct |
30 ms |
32256 KB |
Output is correct |
58 |
Correct |
17 ms |
19072 KB |
Output is correct |
59 |
Correct |
160 ms |
134008 KB |
Output is correct |
60 |
Correct |
101 ms |
90488 KB |
Output is correct |
61 |
Correct |
166 ms |
134120 KB |
Output is correct |
62 |
Correct |
108 ms |
89464 KB |
Output is correct |
63 |
Correct |
160 ms |
134008 KB |
Output is correct |
64 |
Correct |
99 ms |
90540 KB |
Output is correct |
65 |
Correct |
142 ms |
121080 KB |
Output is correct |
66 |
Correct |
127 ms |
111096 KB |
Output is correct |
67 |
Correct |
128 ms |
106488 KB |
Output is correct |
68 |
Correct |
111 ms |
98328 KB |
Output is correct |
69 |
Correct |
129 ms |
119804 KB |
Output is correct |
70 |
Correct |
132 ms |
114808 KB |
Output is correct |
71 |
Correct |
134 ms |
116096 KB |
Output is correct |
72 |
Correct |
128 ms |
117240 KB |
Output is correct |
73 |
Correct |
121 ms |
108920 KB |
Output is correct |
74 |
Correct |
105 ms |
101752 KB |
Output is correct |
75 |
Correct |
119 ms |
112376 KB |
Output is correct |
76 |
Correct |
151 ms |
128760 KB |
Output is correct |
77 |
Correct |
157 ms |
128764 KB |
Output is correct |
78 |
Correct |
110 ms |
99448 KB |
Output is correct |
79 |
Correct |
115 ms |
102904 KB |
Output is correct |
80 |
Correct |
150 ms |
126072 KB |
Output is correct |
81 |
Correct |
118 ms |
104056 KB |
Output is correct |
82 |
Correct |
128 ms |
109944 KB |
Output is correct |
83 |
Correct |
170 ms |
134136 KB |
Output is correct |
84 |
Correct |
132 ms |
114808 KB |
Output is correct |
85 |
Correct |
145 ms |
124792 KB |
Output is correct |
86 |
Correct |
143 ms |
122232 KB |
Output is correct |
87 |
Correct |
129 ms |
112376 KB |
Output is correct |
88 |
Correct |
160 ms |
135292 KB |
Output is correct |
89 |
Correct |
164 ms |
135416 KB |
Output is correct |
90 |
Correct |
137 ms |
113648 KB |
Output is correct |
91 |
Correct |
153 ms |
135288 KB |
Output is correct |
92 |
Correct |
160 ms |
135336 KB |
Output is correct |
93 |
Correct |
159 ms |
132600 KB |
Output is correct |