#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;
}
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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1480 KB |
Output is correct |
2 |
Correct |
17 ms |
17524 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
3 ms |
4044 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
6 ms |
7116 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
3 ms |
3276 KB |
Output is correct |
9 |
Correct |
9 ms |
10972 KB |
Output is correct |
10 |
Correct |
16 ms |
20128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
5 ms |
5188 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
2 ms |
1996 KB |
Output is correct |
6 |
Correct |
10 ms |
10180 KB |
Output is correct |
7 |
Correct |
9 ms |
9860 KB |
Output is correct |
8 |
Correct |
12 ms |
14412 KB |
Output is correct |
9 |
Correct |
2 ms |
2372 KB |
Output is correct |
10 |
Correct |
17 ms |
20112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
49052 KB |
Output is correct |
2 |
Correct |
19 ms |
25924 KB |
Output is correct |
3 |
Incorrect |
111 ms |
144264 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
49052 KB |
Output is correct |
2 |
Correct |
19 ms |
25924 KB |
Output is correct |
3 |
Incorrect |
111 ms |
144264 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
49052 KB |
Output is correct |
2 |
Correct |
19 ms |
25924 KB |
Output is correct |
3 |
Incorrect |
111 ms |
144264 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
448 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
588 KB |
Output is correct |
10 |
Correct |
1 ms |
844 KB |
Output is correct |
11 |
Correct |
1 ms |
844 KB |
Output is correct |
12 |
Correct |
1 ms |
844 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
844 KB |
Output is correct |
15 |
Correct |
1 ms |
836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1480 KB |
Output is correct |
2 |
Correct |
17 ms |
17524 KB |
Output is correct |
3 |
Correct |
2 ms |
1484 KB |
Output is correct |
4 |
Correct |
3 ms |
4044 KB |
Output is correct |
5 |
Correct |
2 ms |
1868 KB |
Output is correct |
6 |
Correct |
6 ms |
7116 KB |
Output is correct |
7 |
Correct |
1 ms |
1228 KB |
Output is correct |
8 |
Correct |
3 ms |
3276 KB |
Output is correct |
9 |
Correct |
9 ms |
10972 KB |
Output is correct |
10 |
Correct |
16 ms |
20128 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
5 ms |
5188 KB |
Output is correct |
14 |
Correct |
1 ms |
716 KB |
Output is correct |
15 |
Correct |
2 ms |
1996 KB |
Output is correct |
16 |
Correct |
10 ms |
10180 KB |
Output is correct |
17 |
Correct |
9 ms |
9860 KB |
Output is correct |
18 |
Correct |
12 ms |
14412 KB |
Output is correct |
19 |
Correct |
2 ms |
2372 KB |
Output is correct |
20 |
Correct |
17 ms |
20112 KB |
Output is correct |
21 |
Correct |
38 ms |
49052 KB |
Output is correct |
22 |
Correct |
19 ms |
25924 KB |
Output is correct |
23 |
Incorrect |
111 ms |
144264 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |