# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1264753 | wedonttalkanymore | Collecting Stamps 3 (JOI20_ho_t3) | C++20 | 0 ms | 836 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 = (ll)1e18, 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] = 0;
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;
int curPos;
if (pos == 0) curPos = x1[l];
else curPos = x[r];
int nxtL = l + 1, nxtR = r + 1;
if (nxtL <= n) {
int newPos = x1[nxtL];
int dist = cur + llabs(newPos - curPos);
int nxtC = c + (dist <= t1[nxtL] ? 1 : 0);
if (dist < dp[nxtL][r][0][nxtC]) dp[nxtL][r][0][nxtC] = dist;
}
if (nxtR <= n) {
int newPos = x[nxtR];
int dist = cur + llabs(newPos - curPos);
int nxtC = c + (dist <= t[nxtR] ? 1 : 0);
if (dist < dp[l][nxtR][1][nxtC]) dp[l][nxtR][1][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;
}
컴파일 시 표준 에러 (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... |