Submission #1067539

#TimeUsernameProblemLanguageResultExecution timeMemory
1067539VMaksimoski008Financial Report (JOI21_financial)C++17
28 / 100
4048 ms502436 KiB
#include <bits/stdc++.h> //#define int long long using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; const int mod = 1e9 + 7; const int LOG = 20; const int maxn = 1e5 + 5; int dp[7005][7005], pref[7005][7005], suf[7005][7005]; signed main() { int n, d; cin >> n >> d; vector<int> v(n+1); set<int> s; for(int i=1; i<=n; i++) cin >> v[i], s.insert(v[i]); vector<int> comp(s.begin(), s.end()); for(int i=1; i<=n; i++) v[i] = lower_bound(comp.begin(), comp.end(), v[i]) - comp.begin(); int m = s.size(); for(int i=1; i<=n; i++) { //prv element dp[i][v[i]] = 1; // for(int k=i-1; k>=max(1, i-d); k--) // for(int j=0; j<v[i]; j++) dp[i][v[i]] = max(dp[i][v[i]], dp[k][j] + 1); for(int k=i-1; k>=max(1, i-d); k--) for(int j=v[i]; j<m; j++) dp[i][j] = max(dp[i][j], dp[k][j]); // for(int k=i-1; k>=max(1, i-d); k--) dp[i][v[i]] = max(dp[i][v[i]], suf[k][v[i]]); for(int k=i-1; k>=max(1, i-d); k--) dp[i][v[i]] = max(dp[i][v[i]], (v[i] >= 1 ? pref[k][v[i]-1] + 1 : 1)); pref[i][0] = dp[i][0]; suf[i][m-1] = dp[i][m-1]; for(int j=1; j<m; j++) pref[i][j] = max(pref[i][j-1], dp[i][j]); for(int j=m-2; j>=0; j--) suf[i][j] = max(suf[i][j+1], dp[i][j]); } int ans = 0; for(int i=0; i<m; i++) ans = max(ans, dp[n][i]); cout << ans << '\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...