#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[9][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<=1;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[0][0][0][0]=0;
for (j=1;j<=m;j++) {
f[0][j][0][1]=a+j*b;
}
res=-1e9;
for (i=1;i<=n;i++) {
for (j=0;j<=m;j++) {
f[i%2][j][0][0]=-1e9;
f[i%2][j][0][1]=-1e9;
f[i%2][j][1][0]=-1e9;
}
f[i%2][0][0][0]=0;
for (j=1;j<=m;j++) {
f[i%2][j][0][1]=a+j*b;
}
for (j=1;j<=m;j++) {
f[i%2][j][0][0]=max({f[(i+1)%2][j][0][1]+a,f[(i+1)%2][j][0][0],f[(i+1)%2][j][1][0]+a})+b;
f[i%2][j][0][1]=max({f[i%2][j-1][1][0]+a,f[i%2][j-1][0][0]+a,f[i%2][j-1][0][1]})+b;
if (s[i]==t[j]) {
f[i%2][j][1][0]=max({f[(i+1)%2][j-1][0][0],f[(i+1)%2][j-1][0][1],f[(i+1)%2][j-1][1][0]})+v[s[i]];
}
}
res=max({res,f[i%2][m][0][0],f[i%2][m][1][0],f[i%2][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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
7 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
9 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
3 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
4 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
6 ms |
360 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
8 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
360 KB |
Output is correct |
3 |
Correct |
53 ms |
332 KB |
Output is correct |
4 |
Correct |
127 ms |
516 KB |
Output is correct |
5 |
Correct |
37 ms |
460 KB |
Output is correct |
6 |
Correct |
55 ms |
460 KB |
Output is correct |
7 |
Correct |
100 ms |
600 KB |
Output is correct |
8 |
Correct |
34 ms |
336 KB |
Output is correct |
9 |
Correct |
66 ms |
476 KB |
Output is correct |
10 |
Correct |
156 ms |
460 KB |
Output is correct |
11 |
Correct |
155 ms |
536 KB |
Output is correct |
12 |
Correct |
155 ms |
460 KB |
Output is correct |
13 |
Correct |
158 ms |
532 KB |
Output is correct |
14 |
Correct |
183 ms |
460 KB |
Output is correct |
15 |
Correct |
183 ms |
516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
360 KB |
Output is correct |
3 |
Correct |
53 ms |
332 KB |
Output is correct |
4 |
Correct |
127 ms |
516 KB |
Output is correct |
5 |
Correct |
37 ms |
460 KB |
Output is correct |
6 |
Correct |
55 ms |
460 KB |
Output is correct |
7 |
Correct |
100 ms |
600 KB |
Output is correct |
8 |
Correct |
34 ms |
336 KB |
Output is correct |
9 |
Correct |
66 ms |
476 KB |
Output is correct |
10 |
Correct |
156 ms |
460 KB |
Output is correct |
11 |
Correct |
155 ms |
536 KB |
Output is correct |
12 |
Correct |
155 ms |
460 KB |
Output is correct |
13 |
Correct |
158 ms |
532 KB |
Output is correct |
14 |
Correct |
183 ms |
460 KB |
Output is correct |
15 |
Correct |
183 ms |
516 KB |
Output is correct |
16 |
Correct |
82 ms |
460 KB |
Output is correct |
17 |
Correct |
106 ms |
472 KB |
Output is correct |
18 |
Correct |
92 ms |
472 KB |
Output is correct |
19 |
Correct |
19 ms |
332 KB |
Output is correct |
20 |
Correct |
64 ms |
332 KB |
Output is correct |
21 |
Correct |
5 ms |
332 KB |
Output is correct |
22 |
Correct |
21 ms |
484 KB |
Output is correct |
23 |
Correct |
40 ms |
460 KB |
Output is correct |
24 |
Correct |
15 ms |
404 KB |
Output is correct |
25 |
Correct |
157 ms |
536 KB |
Output is correct |
26 |
Correct |
156 ms |
540 KB |
Output is correct |
27 |
Correct |
158 ms |
460 KB |
Output is correct |
28 |
Correct |
157 ms |
460 KB |
Output is correct |
29 |
Correct |
196 ms |
524 KB |
Output is correct |
30 |
Correct |
178 ms |
520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
360 KB |
Output is correct |
3 |
Correct |
53 ms |
332 KB |
Output is correct |
4 |
Correct |
127 ms |
516 KB |
Output is correct |
5 |
Correct |
37 ms |
460 KB |
Output is correct |
6 |
Correct |
55 ms |
460 KB |
Output is correct |
7 |
Correct |
100 ms |
600 KB |
Output is correct |
8 |
Correct |
34 ms |
336 KB |
Output is correct |
9 |
Correct |
66 ms |
476 KB |
Output is correct |
10 |
Correct |
156 ms |
460 KB |
Output is correct |
11 |
Correct |
155 ms |
536 KB |
Output is correct |
12 |
Correct |
155 ms |
460 KB |
Output is correct |
13 |
Correct |
158 ms |
532 KB |
Output is correct |
14 |
Correct |
183 ms |
460 KB |
Output is correct |
15 |
Correct |
183 ms |
516 KB |
Output is correct |
16 |
Correct |
131 ms |
508 KB |
Output is correct |
17 |
Correct |
66 ms |
332 KB |
Output is correct |
18 |
Correct |
20 ms |
332 KB |
Output is correct |
19 |
Correct |
6 ms |
332 KB |
Output is correct |
20 |
Correct |
3 ms |
332 KB |
Output is correct |
21 |
Correct |
5 ms |
460 KB |
Output is correct |
22 |
Correct |
60 ms |
460 KB |
Output is correct |
23 |
Correct |
12 ms |
332 KB |
Output is correct |
24 |
Correct |
123 ms |
476 KB |
Output is correct |
25 |
Correct |
154 ms |
552 KB |
Output is correct |
26 |
Correct |
157 ms |
460 KB |
Output is correct |
27 |
Correct |
162 ms |
536 KB |
Output is correct |
28 |
Correct |
158 ms |
460 KB |
Output is correct |
29 |
Correct |
180 ms |
460 KB |
Output is correct |
30 |
Correct |
182 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
456 KB |
Output is correct |
2 |
Correct |
7 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
4 ms |
332 KB |
Output is correct |
10 |
Correct |
9 ms |
376 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
3 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
4 ms |
332 KB |
Output is correct |
17 |
Correct |
4 ms |
332 KB |
Output is correct |
18 |
Correct |
6 ms |
360 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
8 ms |
332 KB |
Output is correct |
21 |
Correct |
17 ms |
376 KB |
Output is correct |
22 |
Correct |
9 ms |
360 KB |
Output is correct |
23 |
Correct |
53 ms |
332 KB |
Output is correct |
24 |
Correct |
127 ms |
516 KB |
Output is correct |
25 |
Correct |
37 ms |
460 KB |
Output is correct |
26 |
Correct |
55 ms |
460 KB |
Output is correct |
27 |
Correct |
100 ms |
600 KB |
Output is correct |
28 |
Correct |
34 ms |
336 KB |
Output is correct |
29 |
Correct |
66 ms |
476 KB |
Output is correct |
30 |
Correct |
156 ms |
460 KB |
Output is correct |
31 |
Correct |
155 ms |
536 KB |
Output is correct |
32 |
Correct |
155 ms |
460 KB |
Output is correct |
33 |
Correct |
158 ms |
532 KB |
Output is correct |
34 |
Correct |
183 ms |
460 KB |
Output is correct |
35 |
Correct |
183 ms |
516 KB |
Output is correct |
36 |
Correct |
82 ms |
460 KB |
Output is correct |
37 |
Correct |
106 ms |
472 KB |
Output is correct |
38 |
Correct |
92 ms |
472 KB |
Output is correct |
39 |
Correct |
19 ms |
332 KB |
Output is correct |
40 |
Correct |
64 ms |
332 KB |
Output is correct |
41 |
Correct |
5 ms |
332 KB |
Output is correct |
42 |
Correct |
21 ms |
484 KB |
Output is correct |
43 |
Correct |
40 ms |
460 KB |
Output is correct |
44 |
Correct |
15 ms |
404 KB |
Output is correct |
45 |
Correct |
157 ms |
536 KB |
Output is correct |
46 |
Correct |
156 ms |
540 KB |
Output is correct |
47 |
Correct |
158 ms |
460 KB |
Output is correct |
48 |
Correct |
157 ms |
460 KB |
Output is correct |
49 |
Correct |
196 ms |
524 KB |
Output is correct |
50 |
Correct |
178 ms |
520 KB |
Output is correct |
51 |
Correct |
131 ms |
508 KB |
Output is correct |
52 |
Correct |
66 ms |
332 KB |
Output is correct |
53 |
Correct |
20 ms |
332 KB |
Output is correct |
54 |
Correct |
6 ms |
332 KB |
Output is correct |
55 |
Correct |
3 ms |
332 KB |
Output is correct |
56 |
Correct |
5 ms |
460 KB |
Output is correct |
57 |
Correct |
60 ms |
460 KB |
Output is correct |
58 |
Correct |
12 ms |
332 KB |
Output is correct |
59 |
Correct |
123 ms |
476 KB |
Output is correct |
60 |
Correct |
154 ms |
552 KB |
Output is correct |
61 |
Correct |
157 ms |
460 KB |
Output is correct |
62 |
Correct |
162 ms |
536 KB |
Output is correct |
63 |
Correct |
158 ms |
460 KB |
Output is correct |
64 |
Correct |
180 ms |
460 KB |
Output is correct |
65 |
Correct |
182 ms |
524 KB |
Output is correct |
66 |
Correct |
1 ms |
332 KB |
Output is correct |
67 |
Correct |
1 ms |
204 KB |
Output is correct |
68 |
Correct |
1 ms |
332 KB |
Output is correct |
69 |
Correct |
1 ms |
204 KB |
Output is correct |
70 |
Correct |
1 ms |
204 KB |
Output is correct |
71 |
Correct |
1 ms |
204 KB |
Output is correct |
72 |
Correct |
1 ms |
332 KB |
Output is correct |
73 |
Correct |
1 ms |
332 KB |
Output is correct |
74 |
Correct |
1 ms |
332 KB |
Output is correct |
75 |
Correct |
1 ms |
204 KB |
Output is correct |
76 |
Correct |
1 ms |
332 KB |
Output is correct |
77 |
Correct |
1 ms |
332 KB |
Output is correct |
78 |
Correct |
1 ms |
332 KB |
Output is correct |
79 |
Correct |
1 ms |
332 KB |
Output is correct |
80 |
Correct |
1 ms |
332 KB |
Output is correct |
81 |
Correct |
137 ms |
588 KB |
Output is correct |
82 |
Correct |
30 ms |
332 KB |
Output is correct |
83 |
Correct |
56 ms |
460 KB |
Output is correct |
84 |
Correct |
30 ms |
468 KB |
Output is correct |
85 |
Correct |
51 ms |
452 KB |
Output is correct |
86 |
Correct |
43 ms |
332 KB |
Output is correct |
87 |
Correct |
8 ms |
336 KB |
Output is correct |
88 |
Correct |
6 ms |
372 KB |
Output is correct |
89 |
Correct |
18 ms |
404 KB |
Output is correct |
90 |
Correct |
174 ms |
524 KB |
Output is correct |
91 |
Correct |
159 ms |
584 KB |
Output is correct |
92 |
Correct |
163 ms |
460 KB |
Output is correct |
93 |
Correct |
160 ms |
516 KB |
Output is correct |
94 |
Correct |
157 ms |
548 KB |
Output is correct |
95 |
Correct |
155 ms |
520 KB |
Output is correct |
96 |
Correct |
158 ms |
460 KB |
Output is correct |
97 |
Correct |
158 ms |
580 KB |
Output is correct |
98 |
Correct |
179 ms |
460 KB |
Output is correct |
99 |
Correct |
186 ms |
580 KB |
Output is correct |
100 |
Correct |
178 ms |
460 KB |
Output is correct |