Submission #654192

#TimeUsernameProblemLanguageResultExecution timeMemory
654192radalFinancial Report (JOI21_financial)C++17
60 / 100
4056 ms5068 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define F first #define S second using namespace std; const int N = 3e5+5; int n, d; int a[N], dp[N], nx[N]; void input() { cin >> n >> d; for (int i = 0; i < n; i++) cin >> a[i]; } void solve1() { int ans = 0; for (int i = n-1; i > -1; i--) { int t = 0; for (int j = i+1; j < n; j++) { if (a[j] <= a[i]) { t = 0; continue; } t++; dp[i] = max(dp[i], dp[j]); if (t == d) break; } dp[i]++; ans = max(ans, dp[i]); } cout << ans << endl; } void solve2() { stack<int> st; for (int i = 0; i < n; i++) { while (st.size() && a[st.top()] < a[i]) { nx[st.top()] = i; st.pop(); } st.push(i); } while (st.size()) { nx[st.top()] = n; st.pop(); } dp[n] = 0; for (int i = n-1; i > -1; i--) dp[i] = dp[nx[i]] + 1; int ans = 1; for (int i = 0; i < n; i++) ans = max(ans, dp[i]); cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); input(); if (d == 1) solve2(); else solve1(); }
#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...