제출 #692656

#제출 시각아이디문제언어결과실행 시간메모리
692656saayan007Visiting Singapore (NOI20_visitingsingapore)C++17
4 / 100
194 ms257120 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pi>; using vpl = vector<pl>; #define fur(i, a, b) for(ll i = a; i <= (ll) b; ++i) #define ruf(i, a, b) for(ll i = a; i >= (ll) b; --i) #define fr first #define sc second #define mp make_pair #define pb push_back #define eb emplace_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define nl "\n" #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template <class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const ll inf = 1e10L; ll cost(ll x, ll y) { if(y & 1) { return 1; } return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll k, n, m, a, b; cin >> k >> n >> m >> a >> b; ll v[k + 1], s[n + 1], t[m + 1]; fur(i, 1, k) { cin >> v[i]; } fur(i, 1, n) { cin >> s[i]; } fur(i, 1, m) { cin >> t[i]; } ll dp[n + 1][m + 1][4]; fur(i, 0, n) { fur(j, 0, m) { fur(x, 0, 3) dp[i][j][x] = -inf; } } dp[1][1][3] = (s[1] == t[1] ? v[s[1]] : -inf); dp[1][1][0] = a; fur(j, 2, m) { dp[1][j][3] = (s[1] == t[j] ? v[s[1]] + a : -inf); dp[1][j][0] = a; } fur(i, 2, n) { dp[i][1][3] = (s[i] == t[1] ? v[s[i]] : -inf); dp[i][1][0] = a; } fur(i, 2, n) { fur(j, 2, m) { if(s[i] == t[j]) { fur(y, 0, 3) dp[i][j][3] = max(dp[i][j][3], dp[i - 1][j - 1][y] + v[s[i]]); } dp[i][j][0] = max({dp[i][j][0], dp[i - 1][j - 1][3] + 2*a, dp[i - 1][j - 1][1] + a, dp[i - 1][j - 1][2] + a, dp[i - 1][j - 1][0]}); dp[i][j][1] = max({dp[i][j][1], dp[i - 1][j][1], dp[i - 1][j][3] + a}); dp[i][j][2] = max({dp[i][j][2], dp[i][j - 1][2], dp[i][j - 1][3] + a}); } } ll res = -inf; fur(i, 1, n) { fur(x, 0, 3) { res = max(res, dp[i][m][x]); } } cout << res << nl; }
#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...