Submission #1087058

#TimeUsernameProblemLanguageResultExecution timeMemory
1087058IcelastCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
128 ms130900 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 205, INF = 4e18+9; struct stamp{ ll x, t; }; ll dp[maxn][maxn][maxn][2]; void solve(){ int n, L; cin >> n >> L; vector<stamp> a(n+2); for(int i = 1; i <= n; i++){ cin >> a[i].x; } for(int i = 1; i <= n; i++){ cin >> a[i].t; } a[0] = {0, INF}; a[n+1] = {0, INF}; auto C = [&](int i, int j) -> ll{ if(a[i].x < a[j].x) swap(i, j); return min(a[i].x - a[j].x, L+(a[j].x-a[i].x)); }; auto chmin = [&](ll &a, ll b) -> void{ a = min(a, b); }; for(int i = 0; i <= n; i++){ for(int j = 0; j <= n; j++){ for(int k = 0; k <= n; k++){ dp[i][j][k][0] = dp[i][j][k][1] = INF; } } } dp[1][n][0][0] = dp[1][n][0][1] = 0; for(int len = n-1; len >= 0; len--){ for(int i = 1; i <= n-len+1; i++){ int j = i+len-1; for(int k = 0; k <= n; k++){ if(i > 1) chmin(dp[i][j][k][0], dp[i-1][j][k][0] + C(i-1, i-1-1)); if(j < n) chmin(dp[i][j][k][1], dp[i][j+1][k][1] + C(j+1, j+1+1)); if(i > 1) chmin(dp[i][j][k][0], dp[i-1][j][k][1] + C(j+1, i-1)); if(j < n) chmin(dp[i][j][k][1], dp[i][j+1][k][0] + C(i-1, j+1)); if(k == 0) continue; if(i > 1 && dp[i-1][j][k-1][0] + C(i-1, i-1-1) <= a[i-1].t) chmin(dp[i][j][k][0], dp[i-1][j][k-1][0] + C(i-1, i-1-1)); if(j < n && dp[i][j+1][k-1][1] + C(j+1, j+1+1) <= a[j+1].t) chmin(dp[i][j][k][1], dp[i][j+1][k-1][1] + C(j+1, j+1+1)); if(i > 1 && dp[i-1][j][k-1][1] + C(j+1, i-1) <= a[i-1].t) chmin(dp[i][j][k][0], dp[i-1][j][k-1][1] + C(j+1, i-1)); if(j < n && dp[i][j+1][k-1][0] + C(i-1, j+1) <= a[j+1].t) chmin(dp[i][j][k][1], dp[i][j+1][k-1][0] + C(i-1, j+1)); } } } int ans = 0; for(int i = 0; i <= n; i++){ for(int j = 0; j <= n; j++){ for(int k = n; k >= 0; k--){ if(min(dp[i][j][k][0], dp[i][j][k][1]) < INF){ ans = max(ans, k); } } } } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); 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...