This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 210, inf = 1e9 + 1;
int dp[N][N][N][2], X[N], T[N];
int32_t main()
{
int n, L; 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 = 0; i <= n + 1; i++) for (int j = 0; j <= n + 1; j++) for (int c = 0; c <= n; c++) dp[i][j][c][0] = dp[i][j][c][1] = inf;
T[0] = T[n+1] = -1;
X[n+1] = L;
dp[0][n+1][0][0] = dp[0][n+1][0][1] = 0;
int ans = 0;
for (int c = 0; c <= n; c++) {
for (int i = 0; i <= n; i++) {
for (int j = n + 1; j > i; j--) {
if (i > 0) {
dp[i][j][c][0] = min(dp[i][j][c][0], min(dp[i - 1][j][c][0] + X[i] - X[i - 1], dp[i - 1][j][c][1] + X[i] + L - X[j]));
if (c > 0 && dp[i - 1][j][c - 1][0] + X[i] - X[i - 1] <= T[i])
dp[i][j][c][0] = min(dp[i][j][c][0], dp[i - 1][j][c - 1][0] + X[i] - X[i - 1]);
if (c > 0 && dp[i - 1][j][c - 1][1] + X[i] + L - X[j] <= T[i])
dp[i][j][c][0] = min(dp[i][j][c][0], dp[i - 1][j][c - 1][1] + X[i] + L - X[j]);
}
if (j < n + 1) {
dp[i][j][c][1] = min(dp[i][j][c][1], min(dp[i][j + 1][c][1] + X[j + 1] - X[j], dp[i][j + 1][c][0] + X[i] + L - X[j]));
if (c > 0 && dp[i][j + 1][c - 1][1] + X[j + 1] - X[j] <= T[j])
dp[i][j][c][1] = min(dp[i][j][c][1], dp[i][j + 1][c - 1][1] + X[j + 1] - X[j]);
if (c > 0 && dp[i][j + 1][c - 1][0] + X[i] + L - X[j] <= T[j])
dp[i][j][c][1] = min(dp[i][j][c][1], dp[i][j + 1][c - 1][0] + X[i] + L - X[j]);
}
if (dp[i][j][c][0] < inf || dp[i][j][c][1] < inf) ans = c;
}
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |