Submission #1126712

#TimeUsernameProblemLanguageResultExecution timeMemory
1126712vladiliusFinancial Report (JOI21_financial)C++20
28 / 100
4093 ms1114112 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, d; cin>>n>>d; vector<int> a(n + 1); vector<pii> all; for (int i = 1; i <= n; i++){ cin>>a[i]; all.pb({a[i], i}); } sort(all.begin(), all.end()); int i = 0, m = 1; while (i < n){ int j = i; while (j < n && all[i].ff == all[j].ff){ a[all[j].ss] = m; j++; } m++; i = j; } vector<vector<int>> dp(n + 1, vector<int>(m + 1)); for (int i = 1; i <= n; i++){ dp[i][a[i]] = 1; for (int j = max(1, i - d); j < i; j++){ dp[i][a[i]] = max({dp[i][a[i]], dp[j][a[i] - 1] + 1, dp[j][a[i]]}); } for (int x = a[i] + 1; x <= m; x++){ dp[i][x] = dp[i][x - 1]; for (int j = max(1, i - d); j < i; j++){ dp[i][x] = max(dp[i][x], dp[j][x]); } } } cout<<dp[n][m]<<"\n"; }
#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...