Submission #1282164

#TimeUsernameProblemLanguageResultExecution timeMemory
1282164shirokitoCollecting Stamps 3 (JOI20_ho_t3)C++20
0 / 100
0 ms332 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int N = 200 + 24;
const ll INF = 1e18;

int n; ll L;
ll x[N], t[N];
pair<ll, ll> dp[N][N][2];

ll dist(ll px, ll py) {
    return min(L - px + py, abs(px - py));
}

void solve() {
    cin >> n >> L;
    for (int i = 1; i <= n; i++) cin >> x[i];
    for (int i = 1; i <= n; i++) cin >> t[i];
    x[0] = L, t[0] = INF; 
    x[n + 1] = L, t[n + 1] = INF; 

    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n + 1; j++) {
            dp[i][j][0] = dp[i][j][1] = {0, INF};
        }
    }

    dp[0][n + 1][0] = dp[0][n + 1][1] = {0, 0};

    for (int i = 0; i <= n + 1; i++) {
        for (int j = n + 1; j >= i + 2; j--) {
            for (int p = 0; p <= 1; p++) {
                ll cnt = dp[i][j][p].first, min_time = dp[i][j][p].second; 
                if (min_time > INF) continue;

                ll new_cnt, new_min_time;

                new_min_time = min_time + dist(x[(p == 0 ? i : j)], x[j - 1]);
                new_cnt = cnt + (new_min_time <= t[j - 1]);
                dp[i][j - 1][1] = max(dp[i][j][p], {new_cnt, new_min_time});

                new_min_time = min_time + dist(x[(p == 0 ? i : j)], x[i + 1]);
                new_cnt = cnt + (new_min_time <= t[i + 1]);
                dp[i + 1][j][0] = max(dp[i + 1][j][0], {new_cnt, new_min_time});
            }
        }
    }

    ll res = 0;
    for (int i = 0; i <= n + 1; i++) {
        for (int j = j + 1; j <= n + 1; j++) {
            for (int p = 0; p <= 1; p++) {
                // cout << i << ' ' << j << ' ' << p << ' ' << dp[i][j][p].first << ' ' << dp[i][j][p].second << '\n';
                res = max(res, dp[i][j][p].first);
            }
        }   
    }

    cout << res << '\n';
}

int main() {
    cin.tie(0) -> sync_with_stdio(0);

    int T = 1; // cin >> T;
    while (T--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...