#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fixbug false
const ll INF = (ll)1e18+7;
const int maxn = 5e3;
int K , n , m ;
ll A , B;
int s[maxn+2] , t[maxn+2] ;
ll v[maxn+2];
namespace subtaskfull{
bool check(){
return true;
}
const ll INF = (ll)1e18+7;
ll dp[maxn+2][2][2]; // FOR the layer , SKIP S , SKIP T
ll tam[maxn+2][2][2];
void main_code(){
memset(dp,-0x3f,sizeof dp);
ll ans = -INF;
for (int i = 0; i <= n; ++i) dp[i][1][1] = 0; // START state
for (int layer = 1; layer <= m; ++layer){
for (int i = 0; i <= n; ++i){
for (int match1 = 0; match1 <= 1; ++match1){
for (int match2 = 0; match2 <= 1; ++match2){
tam[i][match1][match2] = dp[i][match1][match2];
dp[i][match1][match2] = -INF;
if (i==0) dp[i][match1][0] = max(dp[i][match1][0],tam[i][match1][match2] + B + A * match2);
}
}
}
for (int i = 1; i <= n; ++i){
for (int match1 = 0; match1 <= 1; ++match1)
for (int match2 = 0; match2 <= 1; ++match2)
{
if (s[i]==t[layer]){
dp[i][1][1] = max({
dp[i][1][1] ,
tam[i - 1][match1][match2] + v[t[layer]]
});
}
// SKIP S
dp[i][0][match2] = max({
dp[i][0][match2] ,
dp[i-1][match1][match2] + B + A * match1
});
// SKIP T
dp[i][match1][0] = max({
dp[i][match1][0] ,
tam[i][match1][match2] + B + A * match2
});
}
}
}
for (int i = 0; i <= n; ++i){
for (int match1 = 0; match1 <= 1; ++match1){
for (int match2 = 0; match2 <= 1; ++match2){
ans = max(ans , dp[i][match1][match2]);
}
}
}
cout << ans << '\n';
}
}
int main(){
ios::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];
if (subtaskfull::check()){
subtaskfull::main_code();
exit(0);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
8 ms |
656 KB |
Output is correct |
10 |
Correct |
16 ms |
672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
4 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
8 ms |
604 KB |
Output is correct |
7 |
Correct |
8 ms |
652 KB |
Output is correct |
8 |
Correct |
11 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
16 ms |
668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
600 KB |
Output is correct |
2 |
Correct |
14 ms |
604 KB |
Output is correct |
3 |
Correct |
120 ms |
748 KB |
Output is correct |
4 |
Correct |
293 ms |
604 KB |
Output is correct |
5 |
Correct |
85 ms |
604 KB |
Output is correct |
6 |
Correct |
123 ms |
600 KB |
Output is correct |
7 |
Correct |
234 ms |
788 KB |
Output is correct |
8 |
Correct |
75 ms |
604 KB |
Output is correct |
9 |
Correct |
147 ms |
600 KB |
Output is correct |
10 |
Correct |
360 ms |
796 KB |
Output is correct |
11 |
Correct |
363 ms |
604 KB |
Output is correct |
12 |
Correct |
359 ms |
604 KB |
Output is correct |
13 |
Correct |
372 ms |
800 KB |
Output is correct |
14 |
Correct |
392 ms |
600 KB |
Output is correct |
15 |
Correct |
393 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
600 KB |
Output is correct |
2 |
Correct |
14 ms |
604 KB |
Output is correct |
3 |
Correct |
120 ms |
748 KB |
Output is correct |
4 |
Correct |
293 ms |
604 KB |
Output is correct |
5 |
Correct |
85 ms |
604 KB |
Output is correct |
6 |
Correct |
123 ms |
600 KB |
Output is correct |
7 |
Correct |
234 ms |
788 KB |
Output is correct |
8 |
Correct |
75 ms |
604 KB |
Output is correct |
9 |
Correct |
147 ms |
600 KB |
Output is correct |
10 |
Correct |
360 ms |
796 KB |
Output is correct |
11 |
Correct |
363 ms |
604 KB |
Output is correct |
12 |
Correct |
359 ms |
604 KB |
Output is correct |
13 |
Correct |
372 ms |
800 KB |
Output is correct |
14 |
Correct |
392 ms |
600 KB |
Output is correct |
15 |
Correct |
393 ms |
600 KB |
Output is correct |
16 |
Correct |
187 ms |
604 KB |
Output is correct |
17 |
Correct |
230 ms |
604 KB |
Output is correct |
18 |
Correct |
201 ms |
600 KB |
Output is correct |
19 |
Correct |
41 ms |
600 KB |
Output is correct |
20 |
Correct |
146 ms |
600 KB |
Output is correct |
21 |
Correct |
8 ms |
604 KB |
Output is correct |
22 |
Correct |
46 ms |
604 KB |
Output is correct |
23 |
Correct |
91 ms |
600 KB |
Output is correct |
24 |
Correct |
32 ms |
604 KB |
Output is correct |
25 |
Correct |
360 ms |
796 KB |
Output is correct |
26 |
Correct |
359 ms |
600 KB |
Output is correct |
27 |
Correct |
367 ms |
604 KB |
Output is correct |
28 |
Correct |
363 ms |
600 KB |
Output is correct |
29 |
Correct |
396 ms |
600 KB |
Output is correct |
30 |
Correct |
397 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
600 KB |
Output is correct |
2 |
Correct |
14 ms |
604 KB |
Output is correct |
3 |
Correct |
120 ms |
748 KB |
Output is correct |
4 |
Correct |
293 ms |
604 KB |
Output is correct |
5 |
Correct |
85 ms |
604 KB |
Output is correct |
6 |
Correct |
123 ms |
600 KB |
Output is correct |
7 |
Correct |
234 ms |
788 KB |
Output is correct |
8 |
Correct |
75 ms |
604 KB |
Output is correct |
9 |
Correct |
147 ms |
600 KB |
Output is correct |
10 |
Correct |
360 ms |
796 KB |
Output is correct |
11 |
Correct |
363 ms |
604 KB |
Output is correct |
12 |
Correct |
359 ms |
604 KB |
Output is correct |
13 |
Correct |
372 ms |
800 KB |
Output is correct |
14 |
Correct |
392 ms |
600 KB |
Output is correct |
15 |
Correct |
393 ms |
600 KB |
Output is correct |
16 |
Correct |
304 ms |
604 KB |
Output is correct |
17 |
Correct |
141 ms |
604 KB |
Output is correct |
18 |
Correct |
43 ms |
600 KB |
Output is correct |
19 |
Correct |
11 ms |
604 KB |
Output is correct |
20 |
Correct |
6 ms |
648 KB |
Output is correct |
21 |
Correct |
8 ms |
600 KB |
Output is correct |
22 |
Correct |
139 ms |
724 KB |
Output is correct |
23 |
Correct |
27 ms |
600 KB |
Output is correct |
24 |
Correct |
249 ms |
604 KB |
Output is correct |
25 |
Correct |
362 ms |
856 KB |
Output is correct |
26 |
Correct |
360 ms |
600 KB |
Output is correct |
27 |
Correct |
361 ms |
800 KB |
Output is correct |
28 |
Correct |
362 ms |
600 KB |
Output is correct |
29 |
Correct |
396 ms |
604 KB |
Output is correct |
30 |
Correct |
394 ms |
796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
8 ms |
656 KB |
Output is correct |
10 |
Correct |
16 ms |
672 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
4 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
8 ms |
604 KB |
Output is correct |
17 |
Correct |
8 ms |
652 KB |
Output is correct |
18 |
Correct |
11 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
16 ms |
668 KB |
Output is correct |
21 |
Correct |
35 ms |
600 KB |
Output is correct |
22 |
Correct |
14 ms |
604 KB |
Output is correct |
23 |
Correct |
120 ms |
748 KB |
Output is correct |
24 |
Correct |
293 ms |
604 KB |
Output is correct |
25 |
Correct |
85 ms |
604 KB |
Output is correct |
26 |
Correct |
123 ms |
600 KB |
Output is correct |
27 |
Correct |
234 ms |
788 KB |
Output is correct |
28 |
Correct |
75 ms |
604 KB |
Output is correct |
29 |
Correct |
147 ms |
600 KB |
Output is correct |
30 |
Correct |
360 ms |
796 KB |
Output is correct |
31 |
Correct |
363 ms |
604 KB |
Output is correct |
32 |
Correct |
359 ms |
604 KB |
Output is correct |
33 |
Correct |
372 ms |
800 KB |
Output is correct |
34 |
Correct |
392 ms |
600 KB |
Output is correct |
35 |
Correct |
393 ms |
600 KB |
Output is correct |
36 |
Correct |
187 ms |
604 KB |
Output is correct |
37 |
Correct |
230 ms |
604 KB |
Output is correct |
38 |
Correct |
201 ms |
600 KB |
Output is correct |
39 |
Correct |
41 ms |
600 KB |
Output is correct |
40 |
Correct |
146 ms |
600 KB |
Output is correct |
41 |
Correct |
8 ms |
604 KB |
Output is correct |
42 |
Correct |
46 ms |
604 KB |
Output is correct |
43 |
Correct |
91 ms |
600 KB |
Output is correct |
44 |
Correct |
32 ms |
604 KB |
Output is correct |
45 |
Correct |
360 ms |
796 KB |
Output is correct |
46 |
Correct |
359 ms |
600 KB |
Output is correct |
47 |
Correct |
367 ms |
604 KB |
Output is correct |
48 |
Correct |
363 ms |
600 KB |
Output is correct |
49 |
Correct |
396 ms |
600 KB |
Output is correct |
50 |
Correct |
397 ms |
600 KB |
Output is correct |
51 |
Correct |
304 ms |
604 KB |
Output is correct |
52 |
Correct |
141 ms |
604 KB |
Output is correct |
53 |
Correct |
43 ms |
600 KB |
Output is correct |
54 |
Correct |
11 ms |
604 KB |
Output is correct |
55 |
Correct |
6 ms |
648 KB |
Output is correct |
56 |
Correct |
8 ms |
600 KB |
Output is correct |
57 |
Correct |
139 ms |
724 KB |
Output is correct |
58 |
Correct |
27 ms |
600 KB |
Output is correct |
59 |
Correct |
249 ms |
604 KB |
Output is correct |
60 |
Correct |
362 ms |
856 KB |
Output is correct |
61 |
Correct |
360 ms |
600 KB |
Output is correct |
62 |
Correct |
361 ms |
800 KB |
Output is correct |
63 |
Correct |
362 ms |
600 KB |
Output is correct |
64 |
Correct |
396 ms |
604 KB |
Output is correct |
65 |
Correct |
394 ms |
796 KB |
Output is correct |
66 |
Correct |
1 ms |
600 KB |
Output is correct |
67 |
Correct |
0 ms |
600 KB |
Output is correct |
68 |
Correct |
0 ms |
604 KB |
Output is correct |
69 |
Correct |
0 ms |
604 KB |
Output is correct |
70 |
Correct |
0 ms |
604 KB |
Output is correct |
71 |
Correct |
0 ms |
604 KB |
Output is correct |
72 |
Correct |
0 ms |
604 KB |
Output is correct |
73 |
Correct |
0 ms |
604 KB |
Output is correct |
74 |
Correct |
0 ms |
604 KB |
Output is correct |
75 |
Correct |
0 ms |
604 KB |
Output is correct |
76 |
Correct |
1 ms |
604 KB |
Output is correct |
77 |
Correct |
0 ms |
604 KB |
Output is correct |
78 |
Correct |
0 ms |
604 KB |
Output is correct |
79 |
Correct |
0 ms |
604 KB |
Output is correct |
80 |
Correct |
0 ms |
604 KB |
Output is correct |
81 |
Correct |
288 ms |
800 KB |
Output is correct |
82 |
Correct |
67 ms |
604 KB |
Output is correct |
83 |
Correct |
130 ms |
856 KB |
Output is correct |
84 |
Correct |
68 ms |
600 KB |
Output is correct |
85 |
Correct |
114 ms |
600 KB |
Output is correct |
86 |
Correct |
97 ms |
600 KB |
Output is correct |
87 |
Correct |
17 ms |
600 KB |
Output is correct |
88 |
Correct |
11 ms |
604 KB |
Output is correct |
89 |
Correct |
41 ms |
604 KB |
Output is correct |
90 |
Correct |
399 ms |
796 KB |
Output is correct |
91 |
Correct |
365 ms |
604 KB |
Output is correct |
92 |
Correct |
368 ms |
604 KB |
Output is correct |
93 |
Correct |
368 ms |
792 KB |
Output is correct |
94 |
Correct |
360 ms |
604 KB |
Output is correct |
95 |
Correct |
364 ms |
600 KB |
Output is correct |
96 |
Correct |
364 ms |
792 KB |
Output is correct |
97 |
Correct |
368 ms |
604 KB |
Output is correct |
98 |
Correct |
400 ms |
788 KB |
Output is correct |
99 |
Correct |
399 ms |
856 KB |
Output is correct |
100 |
Correct |
394 ms |
792 KB |
Output is correct |