#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;
}
}
}
for (int i = 0; i <= n; ++i){
for (int match1 = 0; match1 <= 1; ++match1)
for (int match2 = 0; match2 <= 1; ++match2)
{
if (s[i]==t[layer]&&i-1>=0){
dp[i][1][1] = max({
dp[i][1][1] ,
tam[i - 1][match1][match2] + v[t[layer]]
});
}
// SKIP S
if (i - 1 >= 0)
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 = 1; i <= n; ++i){
for (int match1 = 0; match1 <= 1; ++match1){
for (int match2 = 0; match2 <= 1; ++match2){
// cout << dp[i][match1][match2] << ' ' << i << ' ' << match1 << ' ' << match2 << '\n';
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 |
15 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
428 KB |
Output is correct |
9 |
Correct |
9 ms |
604 KB |
Output is correct |
10 |
Correct |
18 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
5 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
10 ms |
664 KB |
Output is correct |
7 |
Correct |
8 ms |
652 KB |
Output is correct |
8 |
Correct |
12 ms |
660 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
18 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
604 KB |
Output is correct |
2 |
Correct |
16 ms |
744 KB |
Output is correct |
3 |
Correct |
159 ms |
604 KB |
Output is correct |
4 |
Correct |
315 ms |
604 KB |
Output is correct |
5 |
Correct |
112 ms |
604 KB |
Output is correct |
6 |
Correct |
155 ms |
604 KB |
Output is correct |
7 |
Correct |
246 ms |
776 KB |
Output is correct |
8 |
Correct |
79 ms |
604 KB |
Output is correct |
9 |
Correct |
163 ms |
756 KB |
Output is correct |
10 |
Correct |
382 ms |
836 KB |
Output is correct |
11 |
Correct |
382 ms |
604 KB |
Output is correct |
12 |
Correct |
388 ms |
604 KB |
Output is correct |
13 |
Correct |
380 ms |
604 KB |
Output is correct |
14 |
Correct |
459 ms |
808 KB |
Output is correct |
15 |
Correct |
451 ms |
816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
604 KB |
Output is correct |
2 |
Correct |
16 ms |
744 KB |
Output is correct |
3 |
Correct |
159 ms |
604 KB |
Output is correct |
4 |
Correct |
315 ms |
604 KB |
Output is correct |
5 |
Correct |
112 ms |
604 KB |
Output is correct |
6 |
Correct |
155 ms |
604 KB |
Output is correct |
7 |
Correct |
246 ms |
776 KB |
Output is correct |
8 |
Correct |
79 ms |
604 KB |
Output is correct |
9 |
Correct |
163 ms |
756 KB |
Output is correct |
10 |
Correct |
382 ms |
836 KB |
Output is correct |
11 |
Correct |
382 ms |
604 KB |
Output is correct |
12 |
Correct |
388 ms |
604 KB |
Output is correct |
13 |
Correct |
380 ms |
604 KB |
Output is correct |
14 |
Correct |
459 ms |
808 KB |
Output is correct |
15 |
Correct |
451 ms |
816 KB |
Output is correct |
16 |
Correct |
214 ms |
804 KB |
Output is correct |
17 |
Correct |
243 ms |
604 KB |
Output is correct |
18 |
Correct |
216 ms |
604 KB |
Output is correct |
19 |
Correct |
43 ms |
604 KB |
Output is correct |
20 |
Correct |
153 ms |
768 KB |
Output is correct |
21 |
Correct |
9 ms |
604 KB |
Output is correct |
22 |
Correct |
49 ms |
680 KB |
Output is correct |
23 |
Correct |
101 ms |
604 KB |
Output is correct |
24 |
Correct |
34 ms |
604 KB |
Output is correct |
25 |
Correct |
402 ms |
604 KB |
Output is correct |
26 |
Correct |
384 ms |
604 KB |
Output is correct |
27 |
Correct |
414 ms |
604 KB |
Output is correct |
28 |
Correct |
384 ms |
604 KB |
Output is correct |
29 |
Correct |
437 ms |
600 KB |
Output is correct |
30 |
Correct |
431 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
604 KB |
Output is correct |
2 |
Correct |
16 ms |
744 KB |
Output is correct |
3 |
Correct |
159 ms |
604 KB |
Output is correct |
4 |
Correct |
315 ms |
604 KB |
Output is correct |
5 |
Correct |
112 ms |
604 KB |
Output is correct |
6 |
Correct |
155 ms |
604 KB |
Output is correct |
7 |
Correct |
246 ms |
776 KB |
Output is correct |
8 |
Correct |
79 ms |
604 KB |
Output is correct |
9 |
Correct |
163 ms |
756 KB |
Output is correct |
10 |
Correct |
382 ms |
836 KB |
Output is correct |
11 |
Correct |
382 ms |
604 KB |
Output is correct |
12 |
Correct |
388 ms |
604 KB |
Output is correct |
13 |
Correct |
380 ms |
604 KB |
Output is correct |
14 |
Correct |
459 ms |
808 KB |
Output is correct |
15 |
Correct |
451 ms |
816 KB |
Output is correct |
16 |
Correct |
322 ms |
604 KB |
Output is correct |
17 |
Correct |
159 ms |
792 KB |
Output is correct |
18 |
Correct |
50 ms |
676 KB |
Output is correct |
19 |
Correct |
12 ms |
604 KB |
Output is correct |
20 |
Correct |
6 ms |
660 KB |
Output is correct |
21 |
Correct |
9 ms |
604 KB |
Output is correct |
22 |
Correct |
153 ms |
604 KB |
Output is correct |
23 |
Correct |
27 ms |
600 KB |
Output is correct |
24 |
Correct |
258 ms |
604 KB |
Output is correct |
25 |
Correct |
387 ms |
860 KB |
Output is correct |
26 |
Correct |
385 ms |
600 KB |
Output is correct |
27 |
Correct |
392 ms |
604 KB |
Output is correct |
28 |
Correct |
376 ms |
604 KB |
Output is correct |
29 |
Correct |
439 ms |
812 KB |
Output is correct |
30 |
Correct |
455 ms |
816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
15 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
4 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
428 KB |
Output is correct |
9 |
Correct |
9 ms |
604 KB |
Output is correct |
10 |
Correct |
18 ms |
676 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
10 ms |
664 KB |
Output is correct |
17 |
Correct |
8 ms |
652 KB |
Output is correct |
18 |
Correct |
12 ms |
660 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
18 ms |
604 KB |
Output is correct |
21 |
Correct |
43 ms |
604 KB |
Output is correct |
22 |
Correct |
16 ms |
744 KB |
Output is correct |
23 |
Correct |
159 ms |
604 KB |
Output is correct |
24 |
Correct |
315 ms |
604 KB |
Output is correct |
25 |
Correct |
112 ms |
604 KB |
Output is correct |
26 |
Correct |
155 ms |
604 KB |
Output is correct |
27 |
Correct |
246 ms |
776 KB |
Output is correct |
28 |
Correct |
79 ms |
604 KB |
Output is correct |
29 |
Correct |
163 ms |
756 KB |
Output is correct |
30 |
Correct |
382 ms |
836 KB |
Output is correct |
31 |
Correct |
382 ms |
604 KB |
Output is correct |
32 |
Correct |
388 ms |
604 KB |
Output is correct |
33 |
Correct |
380 ms |
604 KB |
Output is correct |
34 |
Correct |
459 ms |
808 KB |
Output is correct |
35 |
Correct |
451 ms |
816 KB |
Output is correct |
36 |
Correct |
214 ms |
804 KB |
Output is correct |
37 |
Correct |
243 ms |
604 KB |
Output is correct |
38 |
Correct |
216 ms |
604 KB |
Output is correct |
39 |
Correct |
43 ms |
604 KB |
Output is correct |
40 |
Correct |
153 ms |
768 KB |
Output is correct |
41 |
Correct |
9 ms |
604 KB |
Output is correct |
42 |
Correct |
49 ms |
680 KB |
Output is correct |
43 |
Correct |
101 ms |
604 KB |
Output is correct |
44 |
Correct |
34 ms |
604 KB |
Output is correct |
45 |
Correct |
402 ms |
604 KB |
Output is correct |
46 |
Correct |
384 ms |
604 KB |
Output is correct |
47 |
Correct |
414 ms |
604 KB |
Output is correct |
48 |
Correct |
384 ms |
604 KB |
Output is correct |
49 |
Correct |
437 ms |
600 KB |
Output is correct |
50 |
Correct |
431 ms |
604 KB |
Output is correct |
51 |
Correct |
322 ms |
604 KB |
Output is correct |
52 |
Correct |
159 ms |
792 KB |
Output is correct |
53 |
Correct |
50 ms |
676 KB |
Output is correct |
54 |
Correct |
12 ms |
604 KB |
Output is correct |
55 |
Correct |
6 ms |
660 KB |
Output is correct |
56 |
Correct |
9 ms |
604 KB |
Output is correct |
57 |
Correct |
153 ms |
604 KB |
Output is correct |
58 |
Correct |
27 ms |
600 KB |
Output is correct |
59 |
Correct |
258 ms |
604 KB |
Output is correct |
60 |
Correct |
387 ms |
860 KB |
Output is correct |
61 |
Correct |
385 ms |
600 KB |
Output is correct |
62 |
Correct |
392 ms |
604 KB |
Output is correct |
63 |
Correct |
376 ms |
604 KB |
Output is correct |
64 |
Correct |
439 ms |
812 KB |
Output is correct |
65 |
Correct |
455 ms |
816 KB |
Output is correct |
66 |
Correct |
1 ms |
600 KB |
Output is correct |
67 |
Correct |
0 ms |
604 KB |
Output is correct |
68 |
Correct |
1 ms |
604 KB |
Output is correct |
69 |
Correct |
0 ms |
604 KB |
Output is correct |
70 |
Correct |
1 ms |
604 KB |
Output is correct |
71 |
Correct |
1 ms |
604 KB |
Output is correct |
72 |
Correct |
0 ms |
604 KB |
Output is correct |
73 |
Correct |
1 ms |
604 KB |
Output is correct |
74 |
Correct |
1 ms |
604 KB |
Output is correct |
75 |
Correct |
1 ms |
600 KB |
Output is correct |
76 |
Correct |
1 ms |
460 KB |
Output is correct |
77 |
Correct |
0 ms |
604 KB |
Output is correct |
78 |
Correct |
1 ms |
604 KB |
Output is correct |
79 |
Correct |
0 ms |
604 KB |
Output is correct |
80 |
Correct |
1 ms |
460 KB |
Output is correct |
81 |
Correct |
306 ms |
604 KB |
Output is correct |
82 |
Correct |
93 ms |
604 KB |
Output is correct |
83 |
Correct |
136 ms |
604 KB |
Output is correct |
84 |
Correct |
73 ms |
688 KB |
Output is correct |
85 |
Correct |
120 ms |
604 KB |
Output is correct |
86 |
Correct |
106 ms |
604 KB |
Output is correct |
87 |
Correct |
18 ms |
604 KB |
Output is correct |
88 |
Correct |
12 ms |
604 KB |
Output is correct |
89 |
Correct |
66 ms |
604 KB |
Output is correct |
90 |
Correct |
431 ms |
604 KB |
Output is correct |
91 |
Correct |
386 ms |
824 KB |
Output is correct |
92 |
Correct |
391 ms |
828 KB |
Output is correct |
93 |
Correct |
384 ms |
856 KB |
Output is correct |
94 |
Correct |
413 ms |
604 KB |
Output is correct |
95 |
Correct |
405 ms |
812 KB |
Output is correct |
96 |
Correct |
429 ms |
604 KB |
Output is correct |
97 |
Correct |
405 ms |
824 KB |
Output is correct |
98 |
Correct |
456 ms |
604 KB |
Output is correct |
99 |
Correct |
460 ms |
856 KB |
Output is correct |
100 |
Correct |
439 ms |
604 KB |
Output is correct |