Submission #1035269

#TimeUsernameProblemLanguageResultExecution timeMemory
1035269May27_thFinancial Report (JOI21_financial)C++17
60 / 100
4065 ms9200 KiB
#include<bits/stdc++.h> using namespace std; #define i64 long long #define mp make_pair #define all(x) (x).begin(), (x).end() const int MAXN = 300005; const int INF = 1e9 + 7; int N, D, a[MAXN], f[MAXN], r[MAXN], suff[MAXN]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> D; for (int i = 1; i <= N; i ++) cin >> a[i]; stack<int> s; s.push(N + 1); a[N + 1] = INF, r[N + 1] = N + 1; int ans = 0; for (int i = N; i >= 1; i --) { while (!s.empty() && a[s.top()] <= a[i]) s.pop(); r[i] = s.top(); int greater = 1; f[i] = f[s.top()] + 1; for (int j = s.top() + 1; j <= N + 1; j ++) { if (greater >= D || f[i] > suff[j]) break; if (a[j] > a[i]) f[i] = max(f[i], f[j] + 1); else greater = 0; greater += (a[j] > a[i]); } ans = max(ans, f[i]); suff[i] = max(suff[i + 1], f[i]); s.push(i); // cout << i << " " << f[i] << "\n"; } cout << ans << "\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...