Submission #402955

#TimeUsernameProblemLanguageResultExecution timeMemory
402955FidiskVisiting Singapore (NOI20_visitingsingapore)C++14
23 / 100
157 ms262148 KiB
#include <bits/stdc++.h> using namespace std; #define oo 1e15 #define fi first #define se second #define sp(iiii) setprecision(iiii) #define IO ios_base::sync_with_stdio(false); cin.tie(0) #define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa)) #define cntbit(xxxx) __builtin_popcount(xxxx) #define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1) typedef long double ld; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<pair<int,int>,int> piii; typedef pair<long long,long long> pll; typedef pair<pair<long long,long long>,long long> plll; typedef pair<pair<long long,long long>,pair<long long,long long>> pllll; typedef pair<pair<long long,long long>,bool> pllb; const ll base=361; const ll mod=998244353; const ld eps=1e-5; const ll maxn=1e6; int k,n,m,a,b,f[5009][5009][2][2],i,j,s[5009],t[5009],v[5009],res; int main(){ IO; cin>>k>>n>>m>>a>>b; for (i=1;i<=k;i++) { cin>>v[i]; } for (i=1;i<=n;i++) { cin>>s[i]; } for (i=1;i<=m;i++) { cin>>t[i]; } for (i=0;i<=n;i++) { for (j=0;j<=m;j++) { f[i][j][0][0]=-1e9; f[i][j][0][1]=-1e9; f[i][j][1][0]=-1e9; } } for (i=0;i<=n;i++) { f[i][0][0][0]=0; for (j=1;j<=m;j++) { f[i][j][0][0]=a+j*b; } } res=-1e9; for (i=1;i<=n;i++) { for (j=1;j<=m;j++) { f[i][j][0][0]=max(f[i-1][j][0][0],f[i-1][j][1][0]+a)+b; f[i][j][0][1]=max({f[i][j-1][1][0]+a,f[i][j-1][0][0]+a,f[i][j-1][0][1]})+b; if (s[i]==t[j]) { f[i][j][1][0]=max({f[i-1][j-1][0][0],f[i-1][j-1][0][1],f[i-1][j-1][1][0]})+v[s[i]]; } } } for (i=1;i<=n;i++) { res=max({res,f[i][m][0][0],f[i][m][1][0],f[i][m][0][1]}); } /* for (i=1;i<=n;i++) { for (j=1;j<=m;j++) { cout<<f[i][j][0][0]<<' '; } cout<<'\n'; } cout<<'\n'; for (i=1;i<=n;i++) { for (j=1;j<=m;j++) { cout<<f[i][j][0][1]<<' '; } cout<<'\n'; } cout<<'\n'; for (i=1;i<=n;i++) { for (j=1;j<=m;j++) { cout<<f[i][j][1][0]<<' '; } cout<<'\n'; } */ cout<<res<<'\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...