Submission #541319

#TimeUsernameProblemLanguageResultExecution timeMemory
541319JomnoiFinancial Report (JOI21_financial)C++17
65 / 100
1088 ms122568 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int N = 3e5 + 10; const int M = 7e3 + 10; const int INF = 1e9 + 7; int a[N]; int dp[M][M], mx[M]; int main() { cin.tie(0)->sync_with_stdio(0); int n, d; cin >> n >> d; for(int i = 1; i <= n; i++) { cin >> a[i]; } int ans = 0; 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 <= 7000) { vector <int> vec; vec.push_back(-INF); for(int i = 1; i <= n; i++) { vec.push_back(a[i]); } sort(vec.begin(), vec.end()); vec.resize(unique(vec.begin(), vec.end()) - vec.begin()); for(int i = 1; i <= n; i++) { a[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin(); } for(int j = 1; j < vec.size(); j++) { deque <pair <int, int>> dq; for(int i = 1; i <= n; i++) { while(!dq.empty() and dq.front().second < i - d) { dq.pop_front(); } if(j == a[i]) { int ma = 0; for(int k = i - 1; k >= max(1, i - d); k--) { ma = max(ma, mx[k]); } dp[i][j] = ma + 1; } if(j >= a[i] and !dq.empty()) { dp[i][j] = max(dp[i][j], dq.front().first); } while(!dq.empty() and dq.back().first <= dp[i][j]) { dq.pop_back(); } dq.emplace_back(dp[i][j], i); } for(int i = 1; i <= n; i++) { mx[i] = max(mx[i], dp[i][j]); } } ans = mx[n]; } else { assert(false); } cout << ans; return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:60:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int j = 1; j < vec.size(); j++) {
      |                        ~~^~~~~~~~~~~~
#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...