제출 #1243893

#제출 시각아이디문제언어결과실행 시간메모리
1243893sula2Financial Report (JOI21_financial)C++20
17 / 100
31 ms3776 KiB
#include <bits/stdc++.h> #define all(a) (a).begin(), (a).end() #define Z string::npos using namespace std; using namespace chrono; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,d; cin >> n >> d; int a[n]; for (int& x : a) cin >> x; if (d == 1) { vector<int> st; int ans = 0; for (int i = n-1; i >= 0; i--) { while (!st.empty() && a[i] >= a[st.back()]) st.pop_back(); st.push_back(i); ans = max(ans, (int)st.size()); } cout << ans; } else if (d == n) { vector<int> lis; for (int i = 0; i < n; i++) { auto it = lower_bound(all(lis), a[i]); if (it == lis.end()) { lis.push_back(a[i]); } else { *it = a[i]; } } cout << lis.size(); } else if (n <= 7000) { map<int, vector<int>> pos; for (int i = 0; i < n; i++) { pos[a[i]].push_back(i); } int v = 1; for (auto [x, list] : pos) { for (int i : list) { a[i] = v; } v++; } int dp[n][n+1] = {}; for (int i = 0; i < n; i++) { for (int j = i-1; j >= 0 && j >= i-d; j--) { for (int m = 0; m <= n; m++) { dp[i][m] = max(dp[i][m], dp[j][m]); dp[i][max(a[i], m)] = max(dp[i][max(a[i], m)], dp[j][m] + (a[i] > m)); } } // for (int j = 0; j <= n; j++) cout << dp[i][j] << " "; // cout << "\n"; } cout << *max_element(dp[n-1], dp[n-1] + n+1); } }
#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...