// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using pi = pair<int, int>;
using vi = V<int>;
using vpi = V<pi>;
using ll = long long;
using pl = pair<ll, ll>;
using vpl = V<pl>;
using vl = V<ll>;
using db = long double;
template<class T> using pq = priority_queue<T, V<T>, greater<T>>;
const int MOD = 1e9 + 7;
const ll INFL = ll(1e17);
int main() {
cin.tie(0)->sync_with_stdio(0);
int K, N, M, A, B; cin >> K >> N >> M >> A >> B;
vi H(K); for(auto& x : H) cin >> x;
vi S(N); for(auto& x : S) { cin >> x; --x; }
vi T(M); for(auto& x : T) { cin >> x; --x; }
V<V<vi>> dp(2, V<vi>(M+1, vi(2, -MOD)));
// can start on any day
int ans = -MOD;
for(int x = 0; x <= N; x++) {
V<V<vi>> ndp(2, V<vi>(M+1, vi(2, -MOD)));
dp[1][0][1] = 0;
for(int y = 0; y <= M; y++) for(int ys = 0; ys <= 1; ys++) for(int xs = 0; xs <= 1; xs++) {
if (y == M) ans = max(dp[xs][y][ys], ans);
// go to event
if (x < N && y < M && S[x] == T[y]) ndp[1][y+1][1] = max(dp[xs][y][ys] + H[T[y]], ndp[1][y+1][1]);
// skip next event in S (x)
if (x < N) ndp[0][y][ys] = max(dp[xs][y][ys] + B + xs * A, ndp[0][y][ys]);
// skip next event in T (y)
if (y < M) dp[xs][y+1][0] = max(dp[xs][y][ys] + B + ys * A, dp[xs][y+1][0]);
}
dp.swap(ndp);
}
cout << ans << nl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
98 ms |
552 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
27 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
12 ms |
356 KB |
Output is correct |
9 |
Correct |
64 ms |
476 KB |
Output is correct |
10 |
Correct |
131 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
27 ms |
468 KB |
Output is correct |
4 |
Correct |
3 ms |
340 KB |
Output is correct |
5 |
Correct |
9 ms |
440 KB |
Output is correct |
6 |
Correct |
78 ms |
520 KB |
Output is correct |
7 |
Correct |
63 ms |
468 KB |
Output is correct |
8 |
Correct |
81 ms |
548 KB |
Output is correct |
9 |
Correct |
9 ms |
340 KB |
Output is correct |
10 |
Correct |
164 ms |
576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
274 ms |
564 KB |
Output is correct |
2 |
Correct |
106 ms |
424 KB |
Output is correct |
3 |
Correct |
917 ms |
912 KB |
Output is correct |
4 |
Execution timed out |
2074 ms |
1608 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
274 ms |
564 KB |
Output is correct |
2 |
Correct |
106 ms |
424 KB |
Output is correct |
3 |
Correct |
917 ms |
912 KB |
Output is correct |
4 |
Execution timed out |
2074 ms |
1608 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
274 ms |
564 KB |
Output is correct |
2 |
Correct |
106 ms |
424 KB |
Output is correct |
3 |
Correct |
917 ms |
912 KB |
Output is correct |
4 |
Execution timed out |
2074 ms |
1608 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
2 |
Correct |
98 ms |
552 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
27 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
12 ms |
356 KB |
Output is correct |
9 |
Correct |
64 ms |
476 KB |
Output is correct |
10 |
Correct |
131 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
27 ms |
468 KB |
Output is correct |
14 |
Correct |
3 ms |
340 KB |
Output is correct |
15 |
Correct |
9 ms |
440 KB |
Output is correct |
16 |
Correct |
78 ms |
520 KB |
Output is correct |
17 |
Correct |
63 ms |
468 KB |
Output is correct |
18 |
Correct |
81 ms |
548 KB |
Output is correct |
19 |
Correct |
9 ms |
340 KB |
Output is correct |
20 |
Correct |
164 ms |
576 KB |
Output is correct |
21 |
Correct |
274 ms |
564 KB |
Output is correct |
22 |
Correct |
106 ms |
424 KB |
Output is correct |
23 |
Correct |
917 ms |
912 KB |
Output is correct |
24 |
Execution timed out |
2074 ms |
1608 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |