Submission #720674

#TimeUsernameProblemLanguageResultExecution timeMemory
720674JuanCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
453 ms132056 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int maxn = 2e2 + 5, INF = 1e18; int ans = 0, L, mx=0; int dp[maxn][maxn][maxn][2]; int T[maxn], X[maxn]; int32_t main(){ int n; cin >> n >> L; for(int i = 1; i <= n; i++) cin >> X[i]; for(int i = 1; i <= n; i++) cin >> T[i], mx = max(mx, T[i]); for(int i = 0; i <= n+1; i++){ for(int j = 0; j <= n+1; j++){ for(int k = 0; k <= n+1; k++){ dp[i][j][k][0] = dp[i][j][k][1] = INF; } } } priority_queue<tuple<int, int, int, int, int>> pq; pq.push({0, 0, n+1, 0, 0}); dp[0][n+1][0][0] = 0; while(pq.size()){ auto[t, l, r, s, d] = pq.top(); pq.pop(); ans = max(ans, s); if(l==r-1 || t>mx || t>dp[l][r][s][d]) continue; if(d==0){ int t1 = X[l+1]-X[l]; int add1 = (t1+t <= T[l+1]); int &m1 = dp[l+1][r][s+add1][d]; int t2 = X[l]+(L-X[r-1]); int add2 = (t2+t <= T[r-1]); int &m2 = dp[l][r-1][s+add2][1-d]; if(m1 > t+t1) m1= t+t1, pq.push({t+t1, l+1, r, s+add1, d}); if(m2 > t+t2) m2= t+t2, pq.push({t+t2, l, r-1, s+add2, 1-d}); } else{ int t1 = X[r]-X[r-1]; int add1 = (t1+t <= T[r-1]); int &m1 = dp[l][r-1][s+add1][d]; int t2 = X[l+1]+(L-X[r]); int add2 = (t2+t <= T[l+1]); int &m2 = dp[l+1][r][s+add2][1-d]; if(m1 > t+t1) m1= t+t1, pq.push({t+t1, l, r-1, s+add1, d}); if(m2 > t+t2) m2= t+t2, pq.push({t+t2, l+1, r, s+add2, 1-d}); } } 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...