# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
867215 | prohacker | Financial Report (JOI21_financial) | C++14 | 10 ms | 2904 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 7005;
const int INF = INT_MAX;
const int mod = 1e9+7;
int n,rmq[N][15];
int a[N],dp[N];
int D,lg[N];
multiset<int> s;
void pre_calc() {
for(int i = 1 ; i < D ; i++) {
s.insert(a[i]);
}
for(int i = 1 ; i <= n-D+1 ; i++) {
s.insert(a[i+D-1]);
rmq[i][0] = *s.rbegin();
s.erase(s.find(a[i]));
}
for(int j = 1 ; (1 << j) <= n ; j++) {
for(int i = 1 ; i + (1 << j) - 1 <= n ; i++) {
rmq[i][j] = min(rmq[i][j-1],rmq[i+(1<<j-1)][j-1]);
}
}
}
int get(int u, int v) {
int k = lg[v-u+1];
return max(rmq[u][k],rmq[v-(1<<k)+1][k]);
}
signed main()
{
if (fopen("financial.inp", "r")) {
freopen("financial.inp", "r", stdin);
freopen("financial.out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> D;
for(int i = 1 ; i <= n ; i++) {
cin >> a[i];
}
for(int i = 1 ; i <= n ; i++) {
lg[i] = __lg(i);
}
pre_calc();
for(int i = 1 ; i <= n ; i++) {
dp[i] = 1;
for(int j = i-1 ; j > 0 ; j--) {
if(i-j <= D) {
if(a[i] > a[j]) {
dp[i] = max(dp[i],dp[j]+1);
}
}
else {
if(a[j] < a[i] && get(j+1,i-D) <= a[j]) {
dp[i] = max(dp[i],dp[j]+1);
}
}
}
}
cout << *max_element(dp+1,dp+n+1);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |