Submission #224069

#TimeUsernameProblemLanguageResultExecution timeMemory
224069lycCollecting Stamps 3 (JOI20_ho_t3)C++14
100 / 100
97 ms34680 KiB
#include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " :: " << x << endl #define _ << " " << #define SZ(x) (int)(x).size() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define RFOR(i,a,b) for (int i=(a);i>=(b);--i) const int MX_N = 205; const int MX_T = 1e9+5; int N, L; int X[MX_N], T[MX_N]; int atL[MX_N][MX_N][MX_N]; int atR[MX_N][MX_N][MX_N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> L; FOR(i,1,N){ cin >> X[i]; } FOR(i,1,N){ cin >> T[i]; } X[0] = 0; X[N+1] = L; T[0] = T[N+1] = -1; //atL[N+1][0][0] = atR[N+1][0][0] = 0; FOR(l,1,N+1){ FOR(r,0,l-1){ atL[l][r][0] = min(1LL*MX_T, 2LL*X[r] + L-X[l]); atR[l][r][0] = min(1LL*MX_T, 2LL*(L-X[l]) + X[r]); } } int ans = 0; FOR(y,1,N){ FOR(r,0,N){ int mn1 = 2*MX_T, mn2 = 2*MX_T; RFOR(l,N+1,r+1){ atL[l][r][y] = MX_T; if (l < N+1) mn1 = min(mn1, atL[l+1][r][y-1]+X[l+1]); if (l < N+1) mn2 = min(mn2, atR[l+1][r][y-1]+L+X[r]); if (mn1-X[l] <= T[l]) atL[l][r][y] = min(atL[l][r][y], mn1 - X[l]); if (mn2-X[l] <= T[l]) atL[l][r][y] = min(atL[l][r][y], mn2 - X[l]); //FOR(k,l+1,N+1){ // if (atL[k][r][y-1] + X[k]-X[l] <= T[l]) atL[l][r][y] = min(atL[l][r][y], atL[k][r][y-1] + X[k]-X[l]); // if (atR[k][r][y-1] + L-X[l]+X[r] <= T[l]) atL[l][r][y] = min(atL[l][r][y], atR[k][r][y-1] + L-X[l]+X[r]); //} if (atL[l][r][y] < MX_T) ans = max(ans,y); } } FOR(l,1,N+1){ int mn1 = 2*MX_T, mn2 = 2*MX_T; FOR(r,0,l-1){ atR[l][r][y] = MX_T; if (r > 0) mn1 = min(mn1, atR[l][r-1][y-1]-X[r-1]); if (r > 0) mn2 = min(mn2, atL[l][r-1][y-1]+L-X[l]); if (mn1+X[r] <= T[r]) atR[l][r][y] = min(atR[l][r][y], mn1+X[r]); if (mn2+X[r] <= T[r]) atR[l][r][y] = min(atR[l][r][y], mn2+X[r]); //FOR(k,0,r-1){ // if (atR[l][k][y-1] + X[r]-X[k] <= T[r]) atR[l][r][y] = min(atR[l][r][y], atR[l][k][y-1] + X[r]-X[k]); // if (atL[l][k][y-1] + X[r]+L-X[l] <= T[r]) atR[l][r][y] = min(atR[l][r][y], atL[l][k][y-1] + X[r]+L-X[l]); //} if (atR[l][r][y] < MX_T) ans = max(ans,y); } } //TRACE(l _ r _ y _ atL[l][r][y] _ atR[l][r][y]); //cout << flush; //assert(atL[l][r][y] >= 0 && atR[l][r][y] >= 0); } 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...