#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int MXN = 205;
int n, L, a[MXN], t[MXN], ans = 0;
int dp[MXN][MXN][MXN][2];
int dis(int l, int r, bool o) {
if (l > r) swap(l, r);
if (o) return L - (a[r] - a[l]);
return a[r] - a[l];
}
void CALCDP(int l, int r) {
// cout << l << ' ' << r << endl;
dp[l][r][n - (r - l) + 1][0] = INT_MAX;
dp[l][r][n - (r - l) + 1][1] = INT_MAX;
dp[l][r][n - (r - l) + 2][0] = INT_MAX;
dp[l][r][n - (r - l) + 2][1] = INT_MAX;
for (int s = n - (r - l) + 1; s >= 0; s--) {
dp[l][r][s][0] = max(dp[l][r][s][0], dp[l][r][s + 1][0]);
if (r <= n) {
if (dp[l][r + 1][s - 1][0] + dis(r, r + 1, false) <= t[r]) dp[l][r][s][0] = min(dp[l][r][s][0], dp[l][r + 1][s - 1][0] + dis(r, r + 1, false));
if (dp[l][r + 1][s - 1][1] + dis(l, r, true) <= t[r]) dp[l][r][s][0] = min(dp[l][r][s][0], dp[l][r + 1][s - 1][1] + dis(l, r, true));
dp[l][r][s][0] = min(dp[l][r][s][0], dp[l][r + 1][s][0] + dis(r, r + 1, false));
dp[l][r][s][0] = min(dp[l][r][s][0], dp[l][r + 1][s][1] + dis(l, r, true));
if (dp[l][r][s][0] < 2000000000) ans = max(ans, s);
}
dp[l][r][s][1] = max(dp[l][r][s][1], dp[l][r][s + 1][1]);
if (l) {
if (dp[l - 1][r][s - 1][0] + dis(l, r, true) <= t[l]) dp[l][r][s][1] = min(dp[l][r][s][1], dp[l - 1][r][s - 1][0] + dis(l, r, true));
if (dp[l - 1][r][s - 1][1] + dis(l - 1, l, false) < t[l]) dp[l][r][s][1] = min(dp[l][r][s][1], dp[l - 1][r][s - 1][1] + dis(l - 1, l, false));
dp[l][r][s][1] = min(dp[l][r][s][1], dp[l - 1][r][s][0] + dis(l, r, true));
dp[l][r][s][1] = min(dp[l][r][s][1], dp[l - 1][r][s][1] + dis(l - 1, l, false));
if (dp[l][r][s][1] < 2000000000) ans = max(ans, s);
}
}
}
int solve() {
cin >> n >> L;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> t[i];
a[0] = 0;
a[n + 1] = L;
t[0] = -1;
t[n + 1] = -1;
dp[0][n + 1][0][0] = 0;
dp[0][n + 1][0][1] = 0;
for (int i = 1; i < n; i++) {
dp[0][n + 1][i][0] = INT_MAX;
dp[0][n + 1][i][1] = INT_MAX;
}
for (int dif = n; dif >= 0; dif--) {
for (int l = 0; l + dif <= n + 1; l++) {
int r = l + dif;
CALCDP(l, r);
}
}
// cout << dp[0][7][0][0] << endl;
// cout << dp[1][7][1][1] << endl;
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << solve() << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
456 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |