Submission #313376

#TimeUsernameProblemLanguageResultExecution timeMemory
313376sofapudenCollecting Stamps 3 (JOI20_ho_t3)C++14
100 / 100
121 ms133368 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 204; ll n,l, X[maxn], T[maxn], dp[maxn][maxn][2][maxn]; int main(){ ios::sync_with_stdio(0), cin.tie(0); memset(dp, 0x3f, sizeof dp); cin >> n >> l; for(int i = 1; i <= n; ++i)cin >> X[i]; X[n+1] = l; for(int i = 1; i <= n; ++i)cin >> T[i]; ++n; T[0] = -1; dp[0][n][0][0] = 0; dp[0][n][1][0] = 0; int ans = 0; for(int x = n-1; x >= 1; --x){ for(int i = 0; i+x <= n; ++i){ int j = i+x; for(int k = 0; k <= n; ++k){ if(i){ dp[i][j][0][k] = min(dp[i][j][0][k], dp[i-1][j][0][k] + X[i] - X[i-1]); } if(j != n){ dp[i][j][1][k] = min(dp[i][j][1][k], dp[i][j+1][1][k] + X[j+1] - X[j]); } if(k){ if(i && dp[i-1][j][0][k-1] + X[i] - X[i-1] <= T[i]){ dp[i][j][0][k] = min(dp[i][j][0][k], dp[i-1][j][0][k-1] + X[i] - X[i-1]); } if(j != n && dp[i][j+1][1][k-1] + X[j+1] - X[j] <= T[j]){ dp[i][j][1][k] = min(dp[i][j][1][k], dp[i][j+1][1][k-1] + X[j+1] - X[j]); } } dp[i][j][0][k] = min(dp[i][j][0][k], dp[i][j][1][k] + l - X[j] + X[i]); dp[i][j][1][k] = min(dp[i][j][1][k], dp[i][j][0][k] + l - X[j] + X[i]); if(min(dp[i][j][0][k],dp[i][j][1][k]) < 10000000000ll)ans = max(ans,k); } } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...