답안 #733531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733531 2023-05-01T02:24:17 Z Pring Collecting Stamps 3 (JOI20_ho_t3) C++14
0 / 100
1 ms 596 KB
#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);
                // cout << l << ' ' << r << ' ' << 0 << ' ' << s << endl;
            }
        }
        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);
                // cout << l << ' ' << r << ' ' << 1 << ' ' << s << endl;
            }
        }
    }
    dp[l][r][0][0] = a[l] + dis(l, r, true);
    dp[l][r][0][1] = L - a[r] + dis(l, r, true);
}

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[2][11][0][1] << endl;
    return ans;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << solve() << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Incorrect 1 ms 324 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Incorrect 1 ms 324 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Incorrect 1 ms 324 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 456 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Incorrect 1 ms 324 KB Output isn't correct
11 Halted 0 ms 0 KB -