Submission #843804

#TimeUsernameProblemLanguageResultExecution timeMemory
843804fanwenVisiting Singapore (NOI20_visitingsingapore)C++17
30 / 100
214 ms856 KiB
#include <bits/stdc++.h> using namespace std; #define MASK(x) (1LL << (x)) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(x) (x).begin(), (x).end() #define REP(i, n) for (int i = 0, _n = n; i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } template <class A, class B> bool minimize(A &a, B b) { if (a > b) { a = b; return true; } return false; } template <class A, class B> bool maximize(A &a, B b) { if (a < b) { a = b; return true; } return false; } template <class T> T max(const T &a, const T &b, const T &c) { return max(max(a, b), c); } template <class T> T min(const T &a, const T &b, const T &c) { return min(min(a, b), c); } const int MAXN = 5e3 + 5; int N, M, K, A, B; int v[MAXN / 5], s[MAXN], t[MAXN]; int dp[MAXN], Max[MAXN], Max_j[MAXN]; void you_make_it(void) { cin >> K >> N >> M >> A >> B; FOR(i, 1, K) cin >> v[i]; FOR(i, 1, N) cin >> s[i]; FOR(i, 1, M) cin >> t[i]; memset(dp, -0x3f, sizeof dp); memset(Max, -0x3f, sizeof Max); memset(Max_j, -0x3f, sizeof Max_j); long long ans = M * B + A; FOR(i, 1, N) { vector <int> pre_dp(dp, dp + M + 1), pre_Max(Max, Max + M + 1), pre_Max_j(Max_j, Max_j + M + 1); memset(dp, -0x3f, sizeof dp); memset(Max, -0x3f, sizeof Max); memset(Max_j, -0x3f, sizeof Max_j); vector <int> Max_i(M + 1, -2e9); FOR(j, 1, M) { maximize(dp[j], max(pre_Max[j - 1] + (i + j) * B + 2 * A, Max_i[j - 1] + (i + j) * B + A, pre_Max_j[j] + (i + j) * B + A)); if(s[i] == t[j]) { maximize(dp[j], v[s[i]] + A * (j != 1) + (j - 1) * B); maximize(dp[j], pre_dp[j - 1] + v[s[i]]); maximize(ans, dp[j] + A * (j != M) + (M - j) * B); } Max[j] = max(pre_Max[j], Max[j - 1], pre_dp[j] - (i + j) * B); Max_i[j] = max(dp[j] - (i + j) * B, Max_i[j - 1]); Max_j[j] = max(dp[j] - (i + j) * B, pre_Max_j[j]); } } cout << ans; } signed main() { #ifdef LOCAL freopen("TASK.inp", "r", stdin); freopen("TASK.out", "w", stdout); #endif auto start_time = chrono::steady_clock::now(); cin.tie(0), cout.tie(0) -> sync_with_stdio(0); you_make_it(); auto end_time = chrono::steady_clock::now(); cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl; return (0 ^ 0); } // Dream it. Wish it. Do it.
#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...