Submission #419839

#TimeUsernameProblemLanguageResultExecution timeMemory
419839schseFinancial Report (JOI21_financial)C++17
28 / 100
718 ms4176 KiB
#include <bits/stdc++.h> using namespace std; int N, D; vector<int> arr; map<int, int> dp[500]; int rec(int n, int cmax = -1) { int score = arr[n] > cmax ? 1 : 0; int tmp = 0; int cmal = cmax; if (dp[n].count(cmax)) return dp[n][cmax]; if (n == N - 1) return dp[n][cmax] = score; cmax = max(cmax, arr[n]); for (int i = 1; i <= D && i + n <= N - 1; i++) tmp = max(tmp, rec(n + i, cmax)); return dp[n][cmal] = score + tmp; } int main() { cin >> N >> D; arr.resize(N); for (int &i : arr) cin >> i; assert(N <= 400); //compression { vector<int> arr2 = arr; sort(arr2.begin(), arr2.end()); map<int, int> copr; int c = 1; copr[arr2[0]] = ++c; for (int i = 1; i < N; i++) if (arr2[i - 1] < arr2[i]) copr[arr2[i]] = ++c; for (int &i : arr) i = copr[i]; } int score = 0; for (int i = 0; i < N; i++) score = max(score, rec(i)); cout << score; }
#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...