Submission #1018743

#TimeUsernameProblemLanguageResultExecution timeMemory
1018743FIFI_cppCollecting Stamps 3 (JOI20_ho_t3)C++17
100 / 100
47 ms37864 KiB
#include<bits/stdc++.h> using namespace std; const int N = 200; const int inf = 1e9 + 10; int v[N + 2]; int v2[N + 2]; int dp[N + 3][N + 3][N + 3][2]; int main(){ int n,nr; int ans = 0; cin>>n>>nr; v[0] = 0; v2[0] = 100; for(int i = 1;i <= n;i++){ cin>>v[i]; } for(int i = 1;i <= n;i++){ cin>>v2[i]; } v[n + 1] = nr; v2[n + 1] = 100; n+=2; for(int i = 0;i <= n;i++){ for(int j = 0;j <= i;j++){ for(int k = 0;k <= i;k++){ for(int p = 0;p <= 1;p++){ if(i == 0 && j == 0 && k == 0 && p == 0){ dp[i][j][k][p] = 0; }else{ dp[i][j][k][p] = inf; int leftid = n - 1 - (i - j); int rightid = j; int dist = v[rightid] + (nr - v[leftid]); if(i == 0 || leftid <= rightid)continue; if(p == 0){ if(leftid == n - 1)continue; ///to leftside ///from rightside if(k != 0 && dist + dp[i - 1][j][k - 1][1] <= v2[leftid]){ dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j][k - 1][1]); }else{ if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j][k][1]); } ///from leftside if(k != 0 && dp[i - 1][j][k - 1][0] + v[leftid + 1] - v[leftid] <= v2[leftid]){ dp[i][j][k][p] = min(dp[i][j][k][p],dp[i - 1][j][k - 1][0] + v[leftid + 1] - v[leftid]); }else{ if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],dp[i - 1][j][k][0] + v[leftid + 1] - v[leftid]); } }else{ if(j == 0 || rightid == n)continue; ///to rightside ///from leftside if(k != 0 && dist + dp[i - 1][j - 1][k - 1][0] <= v2[rightid]){ dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j - 1][k - 1][0]); }else{ if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j - 1][k][0]); } ///from rightside if(k != 0 && (v[rightid] - v[rightid - 1]) + dp[i - 1][j - 1][k - 1][1] <= v2[rightid]){ dp[i][j][k][p] = min(dp[i][j][k][p],(v[rightid] - v[rightid - 1]) + dp[i - 1][j - 1][k - 1][1]); }else{ if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],(v[rightid] - v[rightid - 1]) + dp[i - 1][j - 1][k][1]); } } if(dp[i][j][k][p] != inf){ ans = max(ans,k); } //cout<<dp[i][j][k][p]<<' '<<i<<' '<<j<<' '<<k<<' '<<p<<' '<<dist<<' '<<leftid<<' '<<v[leftid + 1]<<' '<<v[leftid]<<' '<<(v[rightid] - v[rightid - 1])<<'\n'; } } } } } 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...