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 lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
for (; l != r; ++l)
cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false), cin.tie(0)
#endif
const int N = 205;
int dp[N][N][N][2];
void upd(int &x, int y) {
x = min(x, y);
}
int main () {
owo;
int n, l;
cin >> n >> l;
vector <int> x(n), T(n);
for (int i = 0; i < n; ++i)
cin >> x[i];
for (int i = 0; i < n; ++i)
cin >> T[i];
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k)
dp[i][j][k][0] = dp[i][j][k][1] = 1 << 30;
auto dis = [&](int x, int y) {
int d = abs(y - x);
return min(d, l - d);
};
{
int t = min(x[0], l - x[0]);
dp[1][0][t <= T[0]][0] = t;
}
{
int t = min(x[n - 1], l - x[n - 1]);
dp[0][1][t <= T[n - 1]][1] = t;
}
for (int len = 1; len < n; ++len) for (int l = 0; l <= len; ++l) for (int num = 0; num < n; ++num) {
int r = len - l;
// left to left
if (l && dp[l][r][num][0] != 1 << 30) {
int t = dp[l][r][num][0] + dis(x[l - 1], x[l]);
upd(dp[l + 1][r][num + (t <= T[l])][0], t);
}
// left to right
if (l && dp[l][r][num][0] != 1 << 30) {
int t = dp[l][r][num][0] + dis(x[l - 1], x[n - r - 1]);
upd(dp[l][r + 1][num + (t <= T[n - r - 1])][1], t);
}
// right to left
if (r && dp[l][r][num][1] != 1 << 30) {
int t = dp[l][r][num][1] + dis(x[n - r], x[l]);
upd(dp[l + 1][r][num + (t <= T[l])][0], t);
}
// right to right
if (r && dp[l][r][num][1] != 1 << 30) {
int t = dp[l][r][num][1] + dis(x[n - r], x[n - r - 1]);
upd(dp[l][r + 1][num + (t <= T[n - r - 1])][1], t);
}
}
int ans = 0;
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k) {
if (dp[i][j][k][0] < 1 << 30 || dp[i][j][k][1] < 1 << 30)
ans = max(ans, k);
}
cout << ans << endl;
}
# | 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... |