Submission #751799

#TimeUsernameProblemLanguageResultExecution timeMemory
751799owoovoCollecting Stamps 3 (JOI20_ho_t3)C++14
5 / 100
95 ms108228 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; const ll maxn=1e15; ll n,l,dpl[210][210][210],dpr[210][210][210],x[210],t[210]; ll dis(int a,int b){ if(a<b)swap(a,b); return min(x[a]-x[b],x[b]-x[a]+l); } int main(){ ios::sync_with_stdio(0); cin.tie(0); int ans=0; 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]; for(int i=0;i<=n;i++){ for(int j=0;j<=n;j++){ for(int k=0;k<=n+1;k++){ dpl[i][j][k]=maxn; dpr[i][j][k]=maxn; } } } for(int i=0;i<=n;i++){ dpl[0][i][0]=0; dpr[i][0][0]=0; } for(int i=1;i<=n;i++){ for(int j=0;j<=i;j++){ for(int k=i;k>=0;k--){ dpl[j][i-j][k]=dpl[j][i-j][k+1]; dpr[j][i-j][k]=dpr[j][i-j][k+1]; if(j>0){ dpl[j][i-j][k]=min(dpl[j][i-j][k],min(dpr[j-1][i-j][k]+dis(n+1-(j),i-j),dpl[j-1][i-j][k]+dis(n+1-(j-1),n+1-(j)))); if(k>0&&(dpl[j-1][i-j][k-1]+dis(n+1-(j-1),n+1-j))<=t[n+1-j])dpl[j][i-j][k]=min(dpl[i][i-j][k],dpl[j-1][i-j][k-1]+dis(n+1-(j-1),n+1-j)); if(k>0&&(dpr[j-1][i-j][k-1]+dis(i-j,n+1-j))<=t[n+1-j])dpl[j][i-j][k]=min(dpl[i][i-j][k],dpr[j-1][i-j][k-1]+dis(i-j,n+1-j)); } if(i-j>0){ dpr[j][i-j][k]=min(dpr[j][i-j][k],min(dpr[j][i-j-1][k]+dis(i-j-1,i-j),dpl[j][i-j-1][k]+dis(i-j,n+1-(j)))); if(k>0&&(dpr[j][i-j-1][k-1]+dis(i-j,i-j-1))<=t[i-j])dpr[j][i-j][k]=min(dpr[i][i-j][k],dpr[j][i-j-1][k-1]+dis(i-j,i-j-1)); if(k>0&&(dpl[j][i-j-1][k-1]+dis(i-j,n+1-j))<=t[i-j])dpr[j][i-j][k]=min(dpr[i][i-j][k],dpl[j][i-j-1][k-1]+dis(i-j,n+1-j)); } } } } for(int i=1;i<=n;i++){ for(int j=0;j<=i;j++){ for(int k=0;k<=i;k++){ if(dpl[j][i-j][k]<maxn||dpr[j][i-j][k]<maxn){ 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...