Submission #973966

#TimeUsernameProblemLanguageResultExecution timeMemory
973966AiperiiiCollecting Stamps 3 (JOI20_ho_t3)C++14
100 / 100
84 ms133360 KiB
#include <bits/stdc++.h> #define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; const int N=205; int dp[N][N][N][2],a[N],b[N]; signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n,L; cin>>n>>L; for(int i=1;i<=n;i++)cin>>a[i]; for(int i=1;i<=n;i++)cin>>b[i]; for(int i=0;i<=n+1;i++){ for(int j=0;j<=n+1;j++){ for(int k=0;k<=n;k++){ dp[i][j][k][0]=1e18; dp[i][j][k][1]=1e18; } } } a[n+1]=L; dp[0][n+1][0][0]=0; dp[0][n+1][0][1]=0; for(int l=0;l<=n;l++){ for(int r=n+1;r>l;r--){ for(int k=0;k<=n;k++){ int x=dp[l][r][k][0]+a[l+1]-a[l]; if(x<=b[l+1])dp[l+1][r][k+1][0]=min(dp[l+1][r][k+1][0],x); else dp[l+1][r][k][0]=min(dp[l+1][r][k][0],x); x=dp[l][r][k][1]+L-(a[r]-a[l+1]); if(x<=b[l+1])dp[l+1][r][k+1][0]=min(dp[l+1][r][k+1][0],x); else dp[l+1][r][k][0]=min(dp[l+1][r][k][0],x); x=dp[l][r][k][1]+a[r]-a[r-1]; if(x<=b[r-1])dp[l][r-1][k+1][1]=min(dp[l][r-1][k+1][1],x); else dp[l][r-1][k][1]=min(dp[l][r-1][k][1],x); x=dp[l][r][k][0]+L-(a[r-1]-a[l]); if(x<=b[r-1])dp[l][r-1][k+1][1]=min(dp[l][r-1][k+1][1],x); else dp[l][r-1][k][1]=min(dp[l][r-1][k][1],x); } } } int ans=0; for(int l=0;l<=n;l++){ for(int r=n+1;r>l;r--){ for(int k=0;k<=n;k++){ if(dp[l][r][k][0]!=1e18)ans=max(ans,k); if(dp[l][r][k][1]!=1e18)ans=max(ans,k); } } } 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...