Submission #727163

#TimeUsernameProblemLanguageResultExecution timeMemory
727163NeroZeinFinancial Report (JOI21_financial)C++17
0 / 100
87 ms192512 KiB
#include "bits/stdc++.h" using namespace std; #ifdef Nero #include "Deb.h" #else #define deb(...) #endif const int N = 7005; int a[N]; vector<int> v[N]; int n, d; int dp[N][N]; int bt (int id, int mx) { if (id == n) return 0; int& ret = dp[id][mx]; if (ret != -1) { return ret; } if (a[id] <= mx) { return ret = bt(id + 1, mx); } auto it = lower_bound(v[mx].begin(), v[mx].end(), id); if (mx) { if (it == v[mx].begin()) return 0; it--; if (id - *it > d) return 0; } ret = max(bt(id + 1, mx), bt(id + 1, a[id]) + 1); return ret; } signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> d; vector<int> b(n); for (int i = 0; i < n; ++i) { cin >> a[i]; b[i] = a[i]; } sort(b.begin(), b.end()); b.resize(unique(b.begin(), b.end()) - b.begin()); for (int i = 0; i < n; ++i) { a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1; } memset(dp, -1, sizeof dp); for (int i = 0; i < n; ++i) { v[a[i]].push_back(i); } cout << bt(0, 0) << '\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...