Submission #924069

#TimeUsernameProblemLanguageResultExecution timeMemory
924069rolandpetreanCollecting Stamps 3 (JOI20_ho_t3)C++17
0 / 100
33 ms135256 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll #define endl '\n' #define pb push_back using pi = pair<int, int>; template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int N = 205, INF = 1e14; int n, l; int x[N], t[N]; // dp[l][r][k][0/1] - timpul minim daca iau prefix l, sufix r, k stampile si 0 (sunt pe prefix) sau 1 (sunt pe sufix) int dp[N][N][N][2]; int solve(int l, int r, int k, int w) { if (dp[l][r][k][w] != -1) return dp[l][r][k][w]; dp[l][r][k][w] = INF; if (w == 0) { ckmin(dp[l][r][k][0], solve(l, r, k, 1) + x[n - r + 1]); if (l > 0) { int dist = x[l] - x[l - 1]; int same = solve(l - 1, r, k, 0); ckmin(dp[l][r][k][0], same + dist); if (k > 0) { int take = solve(l - 1, r, k - 1, 0); if (take + dist <= t[l]) ckmin(dp[l][r][k][0], take + dist); } } } else { ckmin(dp[l][r][k][1], solve(l, r, k, 0) + x[l]); if (r > 0) { int dist = x[n - r + 2] - x[n - r + 1]; int same = solve(l, r - 1, k, 1); ckmin(dp[l][r][k][1], same + dist); if (k > 0) { int take = solve(l, r - 1, k - 1, 1); if (take + dist <= t[n - r + 1]) ckmin(dp[l][r][k][1], take + dist); } } } return dp[l][r][k][w]; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); 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] = 0; x[n + 1] = l; memset(dp, -1, sizeof(dp)); for (int w = 0; w <= 1; ++w) dp[0][0][0][w] = 0; int ans = 0; for (int k = 1; k <= n; ++k) { for (int l = 0; l <= n; ++l) { int r = n - l; for (int w = 0; w <= 1; ++w) { if (solve(l, r, k, w) != INF) ans = k; } } } /*for (int k = 0; k <= n; ++k) { for (int i = 0; i <= n; ++i) { cout << i << " " << k << " | " << dp[0][i][k][1] << endl; } }*/ cout << ans; } /* 5 20 4 5 8 13 17 18 23 15 7 10 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...