# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1264757 | wedonttalkanymore | Collecting Stamps 3 (JOI20_ho_t3) | C++20 | 81 ms | 130888 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second
const ll N = 200 + 5, inf = 1e12, mod = 1e9 + 7, block = 320, lim = 16;
int n, L;
int x[N], t[N], x1[N], t1[N];
int dp[N][N][2][N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
if (fopen(".inp", "r")) {
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> n >> L;
for (int i = 1; i <= n; i++) cin >> x[i];
for (int i = 1; i <= n; i++) x1[i] = L - x[n - i + 1];
for (int i = 1; i <= n; i++) cin >> t[i];
for (int i = 1; i <= n; i++) t1[i] = t[n - i + 1];
x[0] = x1[0] = 0;
t[0] = t1[0] = -1;
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= n; ++j)
for (int p = 0; p < 2; ++p)
for (int c = 0; c <= n; ++c)
dp[i][j][p][c] = inf;
dp[0][0][0][0] = dp[0][0][1][0] = 0;
for (int sum = 0; sum <= n; sum++) {
for (int l = 0; l <= sum; l++) {
int r = sum - l;
if (l > n || r > n) continue;
for (int pos = 0; pos < 2; pos++) {
for (int c = 0; c <= n; c++) {
int cur = dp[l][r][pos][c];
if (cur >= inf) continue;
if (pos == 0) {
int nxtL = l + 1, nxtR = r + 1;
if (nxtL <= n) {
int dist = cur + x1[nxtL] - x1[l];
int nxtC = c + (dist <= t1[nxtL] ? 1 : 0);
dp[nxtL][r][pos][nxtC] = min(dp[nxtL][r][pos][nxtC], dist);
}
if (nxtR <= n) {
int dist = cur + x[nxtR] + x1[l];
int nxtC = c + (dist <= t[nxtR] ? 1 : 0);
dp[l][nxtR][1][nxtC] = min(dp[l][nxtR][1][nxtC], dist);
}
}
else if (pos == 1) {
int nxtL = l + 1, nxtR = r + 1;
if (nxtL <= n) {
int dist = cur + x1[nxtL] + x[r];
int nxtC = c + (dist <= t1[nxtL] ? 1 : 0);
dp[nxtL][r][0][nxtC] = min(dp[nxtL][r][0][nxtC], dist);
}
if (nxtR <= n) {
int dist = cur + x[nxtR] - x[r];
int nxtC = c + (dist <= t[nxtR] ? 1 : 0);
dp[l][nxtR][pos][nxtC] = min(dp[l][nxtR][pos][nxtC], dist);
}
}
}
}
}
}
int ans = 0;
for (int sum = 1; sum <= n; sum++) {
for (int l = 0; l <= sum; l++) {
int r = sum - l;
if (l > n || r > n) continue;
for (int pos = 0; pos < 2; pos++) {
for (int c = 0; c <= n; c++) {
if (dp[l][r][pos][c] < inf) ans = max(ans, c);
}
}
}
}
cout << ans;
return 0;
}
Compilation message (stderr)
# | 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... |