제출 #654161

#제출 시각아이디문제언어결과실행 시간메모리
654161FarbodFinancial Report (JOI21_financial)C++17
60 / 100
4072 ms44288 KiB
#include <iostream> #include <vector> using namespace std; const int N = 7005, M = 3e5 + 1; int n, d, a[M], dp[N], ans = 1; bool f[N][N]; void fun1() { vector <int> v; for (int i = n - 1; i >= 0; i--) { while (v.size() && a[v.back()] <= a[i]) v.pop_back(); v.push_back(i); ans = max(ans, (int)v.size()); } cout << ans; return; } signed main() { cin >> n >> d; for (int i = 0; i < n; i++) cin >> a[i]; if (d == 1) { fun1(); return 0; } for (int i = 0; i < n; i++) { vector <int> v; v.push_back(i); for (int j = i - 1; j >= 0; j--) { if (v.back() - j > d) break; if (a[j] < a[i]) v.push_back(j), f[j][i] = 1; } } dp[n - 1] = 1; for (int i = n - 2; i >= 0; i--) { dp[i] = 1; for (int j = i + 1; j < n; j++) if (f[i][j]) dp[i] = max(dp[i], dp[j] + 1); ans = max(ans, dp[i]); } cout << ans; 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...