Submission #1089635

#TimeUsernameProblemLanguageResultExecution timeMemory
1089635dpsaveslivesCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
111 ms135508 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; ll dp[205][205][205][2]; int X[205],T[205]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N,L; 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]; } int ans = 0; memset(dp,0x3f,sizeof(dp)); ll INF = dp[0][0][0][0]; dp[0][0][0][0] = dp[0][0][0][1] = 0; for(int l = 0;l<=N;++l){ for(int r = 0;r<=N;++r){ if(l+r >= N) break; for(int k = 0;k<=l+r;++k){ ll tmp = dp[l][r][k][0]; if(tmp <= INF){ dp[l+1][r][k+(tmp+X[N-l+1]-X[N-l] <= T[N-l])][0] = min(dp[l+1][r][k+(tmp+X[N-l+1]-X[N-l] <= T[N-l])][0],tmp+X[N-l+1]-X[N-l]); dp[l][r+1][k+(tmp+L-X[N-l+1]+X[r+1] <= T[r+1])][1] = min(dp[l][r+1][k+(tmp+L-X[N-l+1]+X[r+1] <= T[r+1])][1],tmp+L-X[N-l+1]+X[r+1]); } tmp = dp[l][r][k][1]; if(tmp <= INF){ dp[l+1][r][k+(tmp+L-X[N-l]+X[r]<=T[N-l])][0] = min(dp[l+1][r][k+(tmp+L-X[N-l]+X[r]<=T[N-l])][0],tmp+L-X[N-l]+X[r]); dp[l][r+1][k+(tmp+X[r+1]-X[r]<=T[r+1])][1]=min(dp[l][r+1][k+(tmp+X[r+1]-X[r]<=T[r+1])][1],tmp+X[r+1]-X[r]); } } } } for(int i = 0;i<=N;++i){ for(int j = 0;j<=N;++j){ for(int k = 0;k<=N;++k){ if(dp[i][j][k][0] != INF){ ans = max(ans,k); } if(dp[i][j][k][1] != INF){ ans = max(ans,k); } } } } cout << ans << "\n"; 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...