Submission #678437

#TimeUsernameProblemLanguageResultExecution timeMemory
678437DP_196Visiting Singapore (NOI20_visitingsingapore)C++14
22 / 100
172 ms196112 KiB
#include <bits/stdc++.h> using namespace std; #define int int64_t #define sz(x) (int)x.size() #define MASK(i) ((1LL) << (i)) #define all(x) x.begin(), x.end() #define BIT(x, i) ((x) >> (i) & (1LL)) #define dbg(...) cerr << "#" << __LINE__ << ":[" << #__VA_ARGS__ \ << "] = [" ,DBG(__VA_ARGS__) string to_string(const string& s) { return '"' + s + '"'; } void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); } template <class T> inline bool maximize(T &a, const T &b) { return (a < b ? (a = b) : 0); } template <class T> inline bool minimize(T &a, const T &b) { return (a > b ? (a = b) : 0); } const int MAXN = 1e5 + 6; const int INF = 1e9; const int MOD = 1e9 + 7; int k, n, m, a, b, v[5005], s[5005], t[5005]; int g[5005][5005]; void sub1() { if (m <= n) return (void) (cout << (v[1] * m)); cout << v[1] * n + (a + (m - n) * b); } void sub2() { for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { g[i][j] = max(g[i - 1][j], g[i][j - 1]); if (s[i] == t[j]) maximize(g[i][j], g[i - 1][j - 1] + v[s[i]]); } cout << g[n][m]; } void sub3() { } void solve() { 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 (k == 1) sub1(); else if (a == 0 && b == 0) sub2(); } #define TASK "" int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen(TASK".inp", "r", stdin); //freopen(TASK".out", "w", stdout); int ntest = 1; //cin >> ntest; while (ntest--) solve(); return 0; } //612
#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...