#include <bits/stdc++.h>
using namespace std;
const int O = 5e3 + 5;
const int inf = 1e9;
int k, n, m, a, b, v[1005], s[O], t[O], f[3][O][O];
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> k >> n >> m >> a >> b;
for (int i = 1; i <= k; ++ i) cin >> v[i];
for (int i = 1; i <= n; ++ i) cin >> s[i];
for (int i = 1; i <= m; ++ i) cin >> t[i];
for (int i = 0; i <= n; ++ i){
for (int j = 1; j <= m; ++ j){
f[0][i][j] = -inf;
f[1][i][j] = -inf;
}
}
for (int j = 0; j <= m; ++ j) f[2][0][j] = b * j;
f[0][0][0] = f[1][0][0] = 0;
for (int i = 1; i <= n; ++ i){
for (int j = 1; j <= m; ++ j){
f[0][i][j] = max(f[0][i - 1][j] + b, f[1][i - 1][j] + a + b);
if (s[i] == t[j]) f[1][i][j] = max({f[2][i - 1][j - 1] + a, f[0][i - 1][j - 1], f[1][i - 1][j - 1]}) + v[s[i]];
f[2][i][j] = max({f[2][i][j - 1], f[1][i][j - 1], f[0][i][j - 1]}) + b;
}
}
int res = a + b * m;
for (int i = 0; i <= n; ++ i){
for (int j = 0; j <= m; ++ j){
int cost = max(f[0][i][j], f[1][i][j]) + a + b * (m - j);
if (j == m) cost -= a;
res = max(res, cost);
}
}
cout << res;
}
Compilation message
VisitingSingapore.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
10 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3148 KB |
Output is correct |
2 |
Correct |
22 ms |
21668 KB |
Output is correct |
3 |
Correct |
3 ms |
3276 KB |
Output is correct |
4 |
Correct |
5 ms |
10956 KB |
Output is correct |
5 |
Correct |
2 ms |
4812 KB |
Output is correct |
6 |
Correct |
8 ms |
12364 KB |
Output is correct |
7 |
Correct |
1 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
6476 KB |
Output is correct |
9 |
Correct |
12 ms |
15236 KB |
Output is correct |
10 |
Correct |
17 ms |
24140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
5 ms |
6604 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
2 ms |
3020 KB |
Output is correct |
6 |
Correct |
13 ms |
13232 KB |
Output is correct |
7 |
Correct |
9 ms |
12076 KB |
Output is correct |
8 |
Correct |
13 ms |
18192 KB |
Output is correct |
9 |
Correct |
3 ms |
4044 KB |
Output is correct |
10 |
Correct |
18 ms |
24136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
60632 KB |
Output is correct |
2 |
Correct |
28 ms |
42188 KB |
Output is correct |
3 |
Correct |
113 ms |
142508 KB |
Output is correct |
4 |
Runtime error |
199 ms |
262148 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
60632 KB |
Output is correct |
2 |
Correct |
28 ms |
42188 KB |
Output is correct |
3 |
Correct |
113 ms |
142508 KB |
Output is correct |
4 |
Runtime error |
199 ms |
262148 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
41 ms |
60632 KB |
Output is correct |
2 |
Correct |
28 ms |
42188 KB |
Output is correct |
3 |
Correct |
113 ms |
142508 KB |
Output is correct |
4 |
Runtime error |
199 ms |
262148 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
0 ms |
716 KB |
Output is correct |
5 |
Correct |
0 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
1228 KB |
Output is correct |
7 |
Correct |
1 ms |
844 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
1612 KB |
Output is correct |
11 |
Correct |
1 ms |
1612 KB |
Output is correct |
12 |
Correct |
1 ms |
1612 KB |
Output is correct |
13 |
Correct |
1 ms |
1612 KB |
Output is correct |
14 |
Correct |
1 ms |
1612 KB |
Output is correct |
15 |
Correct |
1 ms |
1612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3148 KB |
Output is correct |
2 |
Correct |
22 ms |
21668 KB |
Output is correct |
3 |
Correct |
3 ms |
3276 KB |
Output is correct |
4 |
Correct |
5 ms |
10956 KB |
Output is correct |
5 |
Correct |
2 ms |
4812 KB |
Output is correct |
6 |
Correct |
8 ms |
12364 KB |
Output is correct |
7 |
Correct |
1 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
6476 KB |
Output is correct |
9 |
Correct |
12 ms |
15236 KB |
Output is correct |
10 |
Correct |
17 ms |
24140 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
6604 KB |
Output is correct |
14 |
Correct |
1 ms |
1228 KB |
Output is correct |
15 |
Correct |
2 ms |
3020 KB |
Output is correct |
16 |
Correct |
13 ms |
13232 KB |
Output is correct |
17 |
Correct |
9 ms |
12076 KB |
Output is correct |
18 |
Correct |
13 ms |
18192 KB |
Output is correct |
19 |
Correct |
3 ms |
4044 KB |
Output is correct |
20 |
Correct |
18 ms |
24136 KB |
Output is correct |
21 |
Correct |
41 ms |
60632 KB |
Output is correct |
22 |
Correct |
28 ms |
42188 KB |
Output is correct |
23 |
Correct |
113 ms |
142508 KB |
Output is correct |
24 |
Runtime error |
199 ms |
262148 KB |
Execution killed with signal 9 |
25 |
Halted |
0 ms |
0 KB |
- |