Submission #220697

#TimeUsernameProblemLanguageResultExecution timeMemory
220697quocnguyen1012Visiting Singapore (NOI20_visitingsingapore)C++14
100 / 100
229 ms640 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 5e3 + 5, inf = 1e9; int f[2][maxn][2][2]; int val[maxn], s[maxn], t[maxn], A, B, N, M, K; int best(int i, int j) { int res; if(j) res = A + B * j; else res = 0; for(int a = 0; a < 2; ++a) for(int b = 0; b < 2; ++b) res = max(res, f[i][j][a][b]); return res; } signed main(void) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("A.INP", "r", stdin); freopen("A.OUT", "w", stdout); #endif // LOCAL cin >> K >> N >> M >> A >> B; for(int i = 1; i <= K; ++i) cin >> val[i]; for(int i = 1; i <= N; ++i) cin >> s[i]; for(int i = 1; i <= M; ++i) cin >> t[i]; for(int j = 1; j <= M; ++j) for(int a = 0; a < 2; ++a) for(int b = 0; b < 2; ++b) f[0][j][a][b] = -inf; int res = A + M * B; for(int i = 1, z = 1; z <= N; ++z, i ^= 1){ for(int a = 0; a < 2; ++a) for(int b = 0; b < 2; ++b) f[i][0][a][b] = -inf; for(int j = 1; j <= M; ++j){ if(s[z] == t[j]) f[i][j][1][1] = best(i ^ 1, j - 1) + val[s[z]]; else f[i][j][1][1] = -inf; f[i][j][1][0] = max(f[i][j - 1][1][0] + B, f[i][j - 1][1][1] + A + B); f[i][j][0][1] = max(f[i ^ 1][j][0][1] + B, f[i ^ 1][j][1][1] + A + B); f[i][j][0][0] = max(f[i][j - 1][0][0] + B, f[i][j - 1][0][1] + A + B); f[i][j][0][0] = max(f[i][j][0][0], 2 * A + B * (j + 1)); } res = max(res, best(i, M)); } cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...