#include <iostream>
using namespace std;
#define MAXN 205
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 () {
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];
}
tm[0] = tm[n+1] = -1;
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<=l)], 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<=l)], 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 |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
1 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 |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
1 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 |
1152 KB |
Output is correct |
19 |
Correct |
1 ms |
768 KB |
Output is correct |
20 |
Correct |
1 ms |
1024 KB |
Output is correct |
21 |
Correct |
1 ms |
1152 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 |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
1152 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 |
1152 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 |
1276 KB |
Output is correct |
35 |
Correct |
1 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
1 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 |
106232 KB |
Output is correct |
19 |
Correct |
70 ms |
64640 KB |
Output is correct |
20 |
Correct |
33 ms |
34816 KB |
Output is correct |
21 |
Correct |
65 ms |
61140 KB |
Output is correct |
22 |
Correct |
89 ms |
78968 KB |
Output is correct |
23 |
Correct |
27 ms |
29696 KB |
Output is correct |
24 |
Correct |
21 ms |
23296 KB |
Output is correct |
25 |
Correct |
27 ms |
29092 KB |
Output is correct |
26 |
Correct |
9 ms |
11392 KB |
Output is correct |
27 |
Correct |
29 ms |
30208 KB |
Output is correct |
28 |
Correct |
20 ms |
21632 KB |
Output is correct |
29 |
Incorrect |
29 ms |
30848 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
768 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
1 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 |
1152 KB |
Output is correct |
19 |
Correct |
1 ms |
768 KB |
Output is correct |
20 |
Correct |
1 ms |
1024 KB |
Output is correct |
21 |
Correct |
1 ms |
1152 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 |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
1152 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 |
1152 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 |
1276 KB |
Output is correct |
35 |
Correct |
1 ms |
1280 KB |
Output is correct |
36 |
Correct |
122 ms |
106232 KB |
Output is correct |
37 |
Correct |
70 ms |
64640 KB |
Output is correct |
38 |
Correct |
33 ms |
34816 KB |
Output is correct |
39 |
Correct |
65 ms |
61140 KB |
Output is correct |
40 |
Correct |
89 ms |
78968 KB |
Output is correct |
41 |
Correct |
27 ms |
29696 KB |
Output is correct |
42 |
Correct |
21 ms |
23296 KB |
Output is correct |
43 |
Correct |
27 ms |
29092 KB |
Output is correct |
44 |
Correct |
9 ms |
11392 KB |
Output is correct |
45 |
Correct |
29 ms |
30208 KB |
Output is correct |
46 |
Correct |
20 ms |
21632 KB |
Output is correct |
47 |
Incorrect |
29 ms |
30848 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |