#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';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
16 ms |
17412 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 |
3148 KB |
Output is correct |
9 |
Correct |
10 ms |
10956 KB |
Output is correct |
10 |
Correct |
19 ms |
20124 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 |
6 ms |
5096 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 |
10188 KB |
Output is correct |
7 |
Correct |
10 ms |
9804 KB |
Output is correct |
8 |
Correct |
14 ms |
14516 KB |
Output is correct |
9 |
Correct |
3 ms |
2392 KB |
Output is correct |
10 |
Correct |
20 ms |
20004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
48972 KB |
Output is correct |
2 |
Correct |
21 ms |
25884 KB |
Output is correct |
3 |
Correct |
126 ms |
144248 KB |
Output is correct |
4 |
Runtime error |
157 ms |
262148 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
48972 KB |
Output is correct |
2 |
Correct |
21 ms |
25884 KB |
Output is correct |
3 |
Correct |
126 ms |
144248 KB |
Output is correct |
4 |
Runtime error |
157 ms |
262148 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
48972 KB |
Output is correct |
2 |
Correct |
21 ms |
25884 KB |
Output is correct |
3 |
Correct |
126 ms |
144248 KB |
Output is correct |
4 |
Runtime error |
157 ms |
262148 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
704 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 |
2 ms |
844 KB |
Output is correct |
11 |
Correct |
1 ms |
844 KB |
Output is correct |
12 |
Correct |
2 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 |
844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1356 KB |
Output is correct |
2 |
Correct |
16 ms |
17412 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 |
3148 KB |
Output is correct |
9 |
Correct |
10 ms |
10956 KB |
Output is correct |
10 |
Correct |
19 ms |
20124 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
6 ms |
5096 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 |
10188 KB |
Output is correct |
17 |
Correct |
10 ms |
9804 KB |
Output is correct |
18 |
Correct |
14 ms |
14516 KB |
Output is correct |
19 |
Correct |
3 ms |
2392 KB |
Output is correct |
20 |
Correct |
20 ms |
20004 KB |
Output is correct |
21 |
Correct |
42 ms |
48972 KB |
Output is correct |
22 |
Correct |
21 ms |
25884 KB |
Output is correct |
23 |
Correct |
126 ms |
144248 KB |
Output is correct |
24 |
Runtime error |
157 ms |
262148 KB |
Execution killed with signal 9 |
25 |
Halted |
0 ms |
0 KB |
- |