Submission #736721

#TimeUsernameProblemLanguageResultExecution timeMemory
736721veehzFinancial Report (JOI21_financial)C++17
40 / 100
4054 ms476716 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back int main() { int n, d; cin >> n >> d; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; do { // compression vector<int> dd = v; sort(dd.begin(), dd.end()); dd.resize(unique(dd.begin(), dd.end()) - dd.begin()); for (int i = 0; i < n; i++) { v[i] = lower_bound(dd.begin(), dd.end(), v[i]) - dd.begin(); } } while (false); int mx = *max_element(v.begin(), v.end()); if (d == 1) { stack<int> s; int ans = 0; for (int i = n; i--;) { while (s.size() && s.top() <= v[i]) s.pop(); s.push(v[i]); ans = max(ans, (int)s.size()); } cout << ans << endl; return 0; } #ifdef HZLOCAL cout << mx << endl; cout << "V: "; for (auto x : v) cout << x << " "; cout << endl; #endif vector<vector<int>> dp(n, vector<int>(mx + 1, 0)); vector<multiset<int>> cmax(mx + 1); for (int i = 0; i < n; i++) { int prev, cur = 0; for (int j = 0; j <= mx; j++) { prev = cur; if (cmax[j].size()) { cur = max(cur, *cmax[j].rbegin()); } if (j < v[i]) continue; int candidate = max(cur, j ? dp[i][j - 1] : 0); if (v[i] == j) candidate = max(candidate, j ? prev + 1 : 1); dp[i][j] = candidate; } if (i >= d) { for (int j = 0; j <= mx; j++) { cmax[j].erase(cmax[j].find(dp[i - d][j])); } } for (int j = 0; j <= mx; j++) { cmax[j].insert(dp[i][j]); } } #ifdef HZLOCAL for (auto x : dp) { for (auto y : x) cout << y << " "; cout << endl; } #endif cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << endl; }
#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...