#include <bits/stdc++.h>
using namespace std;
#define mod 1'000'000'007
typedef long long ll;
template<typename T>
void deb(initializer_list<T> l)
{
for (auto &e : l)
cout << e << ' ';
cout << endl;
}
int k, n, m, a, b;
vector<int> v, s, t;
int dp[5001][5001][2][2];
void solve()
{
cin >> k >> n >> m >> a >> b;
v.resize(k);
s.resize(n);
t.resize(m);
for (auto &e : v)
cin >> e;
for (auto &e : s)
cin >> e;
for (auto &e : t)
cin >> e;
int i, j, k, l;
for (i = n; i >= 0; --i)
{
for (j = m; j >= 0; --j)
{
for (k = 0; k < 2; ++k)
{
for (l = 0; l < 2; ++l)
{
if (j == m)
dp[i][j][k][l] = (k + l) * a;
else if (i == n)
dp[i][j][k][l] = k * a + a + (m - j) * b;
else
{
dp[i][j][k][l] = max({k * a + a + (m - j) * b,
b + dp[i][j + 1][k][1],
b + dp[i + 1][j][1][l]});
if (s[i] == t[j])
dp[i][j][k][l] = max(dp[i][j][k][l],
dp[i + 1][j + 1][0][0] +
(k + l) * a + v[t[j] - 1]);
}
}
}
}
}
int ans = dp[0][0][0][0];
for (int i = 1; i < n; ++i)
ans = max(ans, dp[i][0][0][0]);
cout << ans << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1408 KB |
Output is correct |
2 |
Correct |
48 ms |
17528 KB |
Output is correct |
3 |
Correct |
5 ms |
1536 KB |
Output is correct |
4 |
Correct |
7 ms |
4096 KB |
Output is correct |
5 |
Correct |
5 ms |
1920 KB |
Output is correct |
6 |
Correct |
14 ms |
7168 KB |
Output is correct |
7 |
Correct |
7 ms |
1280 KB |
Output is correct |
8 |
Correct |
8 ms |
3328 KB |
Output is correct |
9 |
Correct |
22 ms |
11008 KB |
Output is correct |
10 |
Correct |
39 ms |
20088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Correct |
15 ms |
5248 KB |
Output is correct |
4 |
Correct |
6 ms |
768 KB |
Output is correct |
5 |
Correct |
7 ms |
2048 KB |
Output is correct |
6 |
Correct |
20 ms |
10240 KB |
Output is correct |
7 |
Correct |
21 ms |
9984 KB |
Output is correct |
8 |
Correct |
28 ms |
14464 KB |
Output is correct |
9 |
Correct |
9 ms |
2432 KB |
Output is correct |
10 |
Correct |
40 ms |
20088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
49132 KB |
Output is correct |
2 |
Correct |
34 ms |
25976 KB |
Output is correct |
3 |
Correct |
236 ms |
144248 KB |
Output is correct |
4 |
Runtime error |
445 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
49132 KB |
Output is correct |
2 |
Correct |
34 ms |
25976 KB |
Output is correct |
3 |
Correct |
236 ms |
144248 KB |
Output is correct |
4 |
Runtime error |
445 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
49132 KB |
Output is correct |
2 |
Correct |
34 ms |
25976 KB |
Output is correct |
3 |
Correct |
236 ms |
144248 KB |
Output is correct |
4 |
Runtime error |
445 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
512 KB |
Output is correct |
5 |
Correct |
4 ms |
512 KB |
Output is correct |
6 |
Correct |
5 ms |
768 KB |
Output is correct |
7 |
Correct |
5 ms |
640 KB |
Output is correct |
8 |
Correct |
5 ms |
512 KB |
Output is correct |
9 |
Correct |
5 ms |
768 KB |
Output is correct |
10 |
Correct |
5 ms |
896 KB |
Output is correct |
11 |
Correct |
5 ms |
896 KB |
Output is correct |
12 |
Correct |
5 ms |
896 KB |
Output is correct |
13 |
Correct |
5 ms |
896 KB |
Output is correct |
14 |
Correct |
5 ms |
896 KB |
Output is correct |
15 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1408 KB |
Output is correct |
2 |
Correct |
48 ms |
17528 KB |
Output is correct |
3 |
Correct |
5 ms |
1536 KB |
Output is correct |
4 |
Correct |
7 ms |
4096 KB |
Output is correct |
5 |
Correct |
5 ms |
1920 KB |
Output is correct |
6 |
Correct |
14 ms |
7168 KB |
Output is correct |
7 |
Correct |
7 ms |
1280 KB |
Output is correct |
8 |
Correct |
8 ms |
3328 KB |
Output is correct |
9 |
Correct |
22 ms |
11008 KB |
Output is correct |
10 |
Correct |
39 ms |
20088 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
640 KB |
Output is correct |
13 |
Correct |
15 ms |
5248 KB |
Output is correct |
14 |
Correct |
6 ms |
768 KB |
Output is correct |
15 |
Correct |
7 ms |
2048 KB |
Output is correct |
16 |
Correct |
20 ms |
10240 KB |
Output is correct |
17 |
Correct |
21 ms |
9984 KB |
Output is correct |
18 |
Correct |
28 ms |
14464 KB |
Output is correct |
19 |
Correct |
9 ms |
2432 KB |
Output is correct |
20 |
Correct |
40 ms |
20088 KB |
Output is correct |
21 |
Correct |
75 ms |
49132 KB |
Output is correct |
22 |
Correct |
34 ms |
25976 KB |
Output is correct |
23 |
Correct |
236 ms |
144248 KB |
Output is correct |
24 |
Runtime error |
445 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
25 |
Halted |
0 ms |
0 KB |
- |