Submission #224772

#TimeUsernameProblemLanguageResultExecution timeMemory
224772Haunted_CppVisiting Singapore (NOI20_visitingsingapore)C++17
0 / 100
135 ms262148 KiB
#include <iostream> #include <vector> #include <algorithm> #include <bitset> #include <cassert> #include <cstring> typedef long long i64; using namespace std; const int N = 5e3 + 5; int dp [N][N][2][2]; int k, n, m, a, b; int felicidade_evento [N]; int dia_evento [N]; int tarefas [N]; int solve (int p, int task, bool skip_task, bool skip_day) { if (task >= m) { return 0; } if (p >= n) { if (skip_task == false) { return ( a + (m - task) * b); } else { return ( (m - task) * b ); } } int &res = dp[p][task][skip_task][skip_day]; if (~res) return res; res = -1e9; if (tarefas[task] == dia_evento[p]) { res = max (res, felicidade_evento[tarefas[task]] + solve (p + 1, task + 1, false, false)); } else { if (skip_task == false) { res = max (res, a + b + solve (p, task + 1, true, skip_day)); } if (skip_task == true){ res = max (res, b + solve (p, task + 1, true, skip_day)); } if (skip_day == false) { res = max (res, a + b + solve (p + 1, task, skip_task, true)); } if (skip_day == true) { res = max (res, b + solve (p + 1, task, skip_task, true)); } } return res; } int main () { ios::sync_with_stdio(0); cin.tie(0); cin >> k >> n >> m >> a >> b; for (int i = 1; i <= k; i++) cin >> felicidade_evento[i]; for (int i = 0; i < n; i++) cin >> dia_evento[i]; for (int i = 0; i < m; i++) cin >> tarefas[i]; memset (dp, -1, sizeof(dp)); int mn = -1e9; for (int i = 0; i < n; i++) { mn = max (mn, solve (i, 0, false, false)); } cout << mn << '\n'; return 0; }
#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...