Submission #1000380

# Submission time Handle Problem Language Result Execution time Memory
1000380 2024-06-17T10:53:52 Z makrav Collecting Stamps 3 (JOI20_ho_t3) C++14
0 / 100
36 ms 127312 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first 
#define sc second 
#define pb push_back
#define int ll

int dp[201][201][201][2];

signed main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int n, l; cin >> n >> l;
    vector<int> x(n + 1, 0);
    for (int i = 1; i <= n; i++) cin >> x[i];
    vector<int> t(n + 1, 0);
    for (int i = 1; i <= n; i++) cin >> t[i];
    auto getd = [&](int i, int j) {
        return min(abs(x[i] - x[j]), l - abs(x[i] - x[j]));
    };
    for (int i = 0; i <= 200; i++) {
        for (int j = 0; j <= 200;j++) {
            for (int cnt = 0; cnt <= 200; cnt++) {
                for (int I = 0; I < 2; I++) dp[i][j][cnt][I] = 1e15;
            }
        }
    }
    dp[1][0][1][0] = 0;
    dp[1][0][1][1] = 0;
    for (int cnt = 2; cnt <= n + 1; cnt++) {
        for (int left = 1; left <= cnt; left++) {
            int right = cnt - left;
            for (int C = 1; C <= cnt; C++) {
                auto relax = [&](int side, int val) {
                    if (val < 1e15) {
                        dp[left][right][C][side] = min(dp[left][right][C][side], val);
                    }
                };
                {
                    int prev_left = (left == 1 ? n : left - 2);
                    int prev_right = (right == 0 ? 0 : n - right + 1);
                    if (dp[left - 1][right][C - 1][0] + getd(prev_left, left - 1) <= t[left - 1]) {
                        relax(0, dp[left - 1][right][C - 1][0] + getd(prev_left, left - 1));
                    }
                    if (dp[left - 1][right][C][0] + getd(prev_left, left - 1) > t[left - 1]) {
                        relax(0, dp[left - 1][right][C][0] + getd(prev_left, left - 1));
                    }
                    if (dp[left - 1][right][C - 1][1] + getd(prev_right, left - 1) <= t[left - 1]) {
                        relax(0, dp[left - 1][right][C - 1][1] + getd(prev_right, left - 1));
                    }
                    if (dp[left - 1][right][C][1] + getd(prev_right, left - 1) > t[left - 1]) {
                        relax(0, dp[left - 1][right][C][1] + getd(prev_right, left - 1));
                    }
                }
                if (right) {
                    int prev_left = left - 1, prev_right = (right == 1 ? 0 : n - (right - 1) + 1);
                    int cur = n - right + 1;
                    if (dp[left][right - 1][C - 1][0] + getd(prev_left, cur) <= t[cur]) {
                        relax(1, dp[left][right - 1][C - 1][0] + getd(prev_left, cur));
                    }
                    if (dp[left][right - 1][C][0] + getd(prev_left, cur) > t[cur]) {
                        relax(1, dp[left][right - 1][C][0] + getd(prev_left, cur));
                    }
                    if (dp[left][right - 1][C - 1][1] + getd(prev_right, cur) <= t[cur]) {
                        relax(1, dp[left][right - 1][C - 1][1] + getd(prev_right, cur));
                    }
                    if (dp[left][right - 1][C][1] + getd(prev_right, cur) > t[cur]) {
                        relax(1, dp[left][right - 1][C][1] + getd(prev_right, cur));
                    }
                }
            }
        }
    }
    int ans = 0;
    for (int left = 1; left <= n + 1; left++) {
        for (int cnt = 1; cnt <= n + 1; cnt++) {
            if (dp[left][n + 1 - left][cnt][0] < 1e15 || dp[left][n + 1 - left][cnt][1] < 1e18) ans = max(ans, cnt); 
        }
    }
    cout << ans - 1 << '\n';

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 127312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 127312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 127312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 127312 KB Output isn't correct
2 Halted 0 ms 0 KB -