Submission #1264754

#TimeUsernameProblemLanguageResultExecution timeMemory
1264754wedonttalkanymoreCollecting Stamps 3 (JOI20_ho_t3)C++20
0 / 100
0 ms580 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];
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++) cin >> t[i];

    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 = (l == 0 ? 0 : x[l]);
                    } else {
                        curPos = (r == 0 ? L : x[n - r + 1]);
                    }

                    // pick next from left: index = l+1
                    int nxtL = l + 1;
                    if (nxtL <= n) {
                        int idx = nxtL;
                        int newPos = x[idx];
                        int dist = cur + llabs(newPos - curPos);
                        int nxtC = c + (dist <= t[idx] ? 1 : 0);
                        if (dist < dp[nxtL][r][0][nxtC]) dp[nxtL][r][0][nxtC] = dist;
                    }

                    // pick next from right: index = n - r
                    int nxtR = r + 1;
                    int idxR = n - r;
                    if (idxR >= 1) {
                        int idx = idxR;
                        int newPos = x[idx];
                        int dist = cur + llabs(newPos - curPos);
                        int nxtC = c + (dist <= t[idx] ? 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;
}

Compilation message (stderr)

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen(".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...