Submission #256350

#TimeUsernameProblemLanguageResultExecution timeMemory
256350vioalbertCollecting Stamps 3 (JOI20_ho_t3)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 205, INF = 1e18; ll n, l; ll cl[N], ccl[N], t[N]; void read() { cin >> n >> l; cl[0] = 0, cl[n+1] = l; ccl[0] = l, cl[n+1] = 0; for(int i = 1; i <= n; i++) { cin >> cl[i]; ccl[i] = l - cl[i]; } for(int i = 1; i <= n; i++) cin >> t[i]; } struct state { int l, r, cnt, dir; state(int _l, int _r, int _cnt, int _dir) : l(_l), r(_r), cnt(_cnt), dir(_dir) {} bool operator<(const state& ot) const { return cnt < ot.cnt; } }; void solve() { priority_queue<pair<ll, state>, vector<pair<ll, state>>, greater<pair<ll, state>>> pq; ll dp[n+2][n+2][n+2][2]; for(int l = 0; l <= n+1; l++) { for(int r = 0; r <= n+1; r++) { for(int cnt = 0; cnt <= n; cnt++) dp[l][r][cnt][0] = dp[l][r][cnt][1] = INF; } } dp[0][n+1][0][0] = 0; for(int l = 0; l <= n+1; l++) { for(int r = n+1; r > l; r--) { for(int cnt = 0; cnt <= n; cnt++) { // cerr << l << ' ' << r << ' ' << cnt << '\n'; ll dur; if(dp[l][r][cnt][0] < INF) { dur = dp[l][r][cnt][0] + cl[l + 1] - cl[l]; dp[l + 1][r][cnt + (dur <= t[l + 1])][0] = min(dp[l + 1][r][cnt + (dur <= t[l + 1])][0], dur); dur = dp[l][r][cnt][0] + cl[l] + ccl[r - 1]; dp[l][r - 1][cnt + (dur <= t[r - 1])][1] = min(dp[l][r - 1][cnt + (dur <= t[r - 1])][1], dur); } if(dp[l][r][cnt][1] < INF) { dur = dp[l][r][cnt][1] + ccl[r - 1] - ccl[r]; dp[l][r - 1][cnt + (dur <= t[r - 1])][1] = min(dp[l][r - 1][cnt + (dur <= t[r - 1])][1], dur); dur = dp[l][r][cnt][1] + ccl[r] + cl[l + 1]; dp[l + 1][r][cnt + (dur <= t[l + 1])][0] = min(dp[l + 1][r][cnt + (dur <= t[l + 1])][0], dur); } } } } ll ans = 0; for(int l = 0; l <= n; l++) { for(int r = 0; r <= n; r++) { for(int cnt = 0; cnt <= n; cnt++) { if(min(dp[l][r][cnt][0], dp[l][r][cnt][1]) < INF) ans = max(ans, (ll)cnt); } } } cout << ans << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); read(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...