#include <iostream>
using namespace std;
#define MAXN 205
int n, l;
int 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++) {
if (dp[i][j][0][k]+dist[i+1]-dist[i] <= tm[i+1]) {
dp[i+1][j][0][k+1] = min(dp[i+1][j][0][k+1], dp[i][j][0][k]+dist[i+1]-dist[i]);
} else {
dp[i+1][j][0][k] = min(dp[i+1][j][0][k], dp[i][j][0][k]+dist[i+1]-dist[i]);
}
if (dp[i][j][1][k]+dist[i+1]+l-dist[j] <= tm[i+1]) {
dp[i+1][j][0][k+1] = min(dp[i+1][j][0][k+1], dp[i][j][1][k]+dist[i+1]-dist[i]);
} else {
dp[i+1][j][0][k] = min(dp[i+1][j][0][k], dp[i][j][1][k]+dist[i+1]-dist[i]);
}
if (dp[i][j][1][k]+dist[j]-dist[j-1] <= tm[j-1]) {
dp[i][j-1][1][k+1] = min(dp[i][j-1][1][k+1], dp[i][j][1][k]+dist[j]-dist[j-1]);
} else {
dp[i][j-1][1][k] = min(dp[i][j-1][1][k], dp[i][j][1][k]+dist[j]-dist[j-1]);
}
if (dp[i][j][0][k]+dist[i]+l-dist[j-1] <= tm[j-1]) {
dp[i][j-1][1][k+1] = min(dp[i][j-1][1][k+1], dp[i][j][0][k]+dist[i]+l-dist[j-1]);
} else {
dp[i][j-1][1][k] = min(dp[i][j-1][1][k], dp[i][j][0][k]+dist[i]+l-dist[j-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++) {
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 |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Incorrect |
1 ms |
1024 KB |
Output isn't correct |
14 |
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 |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Incorrect |
1 ms |
1024 KB |
Output isn't correct |
14 |
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 |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Incorrect |
1 ms |
1024 KB |
Output isn't correct |
14 |
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 |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Incorrect |
1 ms |
1024 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |