Submission #541317

#TimeUsernameProblemLanguageResultExecution timeMemory
541317JomnoiFinancial Report (JOI21_financial)C++17
31 / 100
46 ms5508 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int N = 3e5 + 10; int n, d; int ans; int a[N]; void solve(int i, int ma, int cnt) { if(i > n) { return; } if(ma < a[i]) { ma = a[i]; cnt++; } ans = max(ans, cnt); for(int j = 1; j <= d; j++) { solve(i + j, ma, cnt); } } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> d; for(int i = 1; i <= n; i++) { cin >> a[i]; } if(d == 1) { int ma = 0; stack <int> stk; for(int i = n; i >= 1; i--) { while(!stk.empty() and stk.top() <= a[i]) { stk.pop(); } stk.push(a[i]); ma = max(ma, (int)stk.size()); } ans = ma; } else if(d == n) { vector <int> lis; for(int i = 1; i <= n; i++) { auto it = lower_bound(lis.begin(), lis.end(), a[i]); if(it == lis.end()) { lis.push_back(a[i]); } else { *it = a[i]; } } ans = lis.size(); } else if(n <= 20) { for(int i = n; i > 0; i--) { solve(i, -1, 0); } } else { assert(false); } 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...