#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 , Match S , Match 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 = 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 = 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);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
14 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
1016 KB |
Output is correct |
6 |
Correct |
4 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
8 ms |
604 KB |
Output is correct |
10 |
Correct |
17 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
5 ms |
648 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 |
604 KB |
Output is correct |
8 |
Correct |
11 ms |
660 KB |
Output is correct |
9 |
Correct |
2 ms |
600 KB |
Output is correct |
10 |
Correct |
16 ms |
676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
600 KB |
Output is correct |
3 |
Incorrect |
120 ms |
768 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
600 KB |
Output is correct |
3 |
Incorrect |
120 ms |
768 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
604 KB |
Output is correct |
2 |
Correct |
14 ms |
600 KB |
Output is correct |
3 |
Incorrect |
120 ms |
768 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
14 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
1016 KB |
Output is correct |
6 |
Correct |
4 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
8 ms |
604 KB |
Output is correct |
10 |
Correct |
17 ms |
604 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 |
648 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 |
604 KB |
Output is correct |
18 |
Correct |
11 ms |
660 KB |
Output is correct |
19 |
Correct |
2 ms |
600 KB |
Output is correct |
20 |
Correct |
16 ms |
676 KB |
Output is correct |
21 |
Correct |
36 ms |
604 KB |
Output is correct |
22 |
Correct |
14 ms |
600 KB |
Output is correct |
23 |
Incorrect |
120 ms |
768 KB |
Output isn't correct |
24 |
Halted |
0 ms |
0 KB |
- |