Submission #680197

#TimeUsernameProblemLanguageResultExecution timeMemory
680197fdnfksdVisiting Singapore (NOI20_visitingsingapore)C++14
23 / 100
241 ms262144 KiB
#include<bits/stdc++.h> #define TASKNAME "codeforce" #define pb push_back #define pli pair<int,int> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; using ll=int; const ll maxN=5005; const ll inf=1e9; ll mn2[5005][5005],mn1[5005][5005]; ll k,n,m,a,b,s[maxN],v[maxN],t[maxN]; ll dp[5005][5005]; void update(ll i,ll j,ll val) { mn1[i][j]=max(mn1[i][j-1],val); mn2[i][j]=max(mn2[i-1][j],val); dp[i][j]=max(dp[i-1][j],dp[i][j-1]); dp[i][j]=max(dp[i][j],val); } void solve() { cin >> k >> n >> m >> a >> b; for(int i=1;i<=k;i++) cin >> v[i]; for(int i=1;i<=n;i++) cin >> s[i]; for(int i=1;i<=m;i++) cin >> t[i]; dp[0][0]=mn1[0][0]=mn2[0][0]=-inf; for(int i=1;i<=n;i++) { dp[i][0]=dp[0][i]=mn1[i][0]=mn1[0][i]=mn2[0][i]=mn2[i][0]=-inf; } ll ans=-inf; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(s[i]==t[j]) { if(i<=1||j<=1) dp[i][j]=-inf; dp[i][j]=max(dp[i][j],v[s[i]]+(a*(j>1)+b*(j-1))); ll x; x=mn1[i-1][j-1]; dp[i][j]=max(dp[i][j],x+i*b+j*b-2*b+a+v[s[i]]); x=mn2[i-1][j-1]; dp[i][j]=max(dp[i][j],x+i*b+j*b-2*b+a+v[s[i]]); if(i>=2&&j>=2) { x=dp[i-2][j-2]; dp[i][j]=max(dp[i][j],x+i*b+j*b-2*b+2*a+v[s[i]]); } } else { dp[i][j]=-inf; } dp[i+1][j+1]=dp[i][j]+v[s[i+1]]; ans=max(ans,dp[i][j]+(a*(m>j)+b*(m-j))); update(i,j,dp[i][j]-b*i-b*j); } } cout << max(ans,a+b*m); } int main() { fastio //freopen(TASKNAME".INP","r",stdin); //freopen(TASKNAME".OUT","w",stdout); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...