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 mod 1000000007LL
#define inf 1e17
#define ll long long
using namespace std;
void printvec(vector<ll> vec) {
for (auto &&e : vec) {
cout << e << ' ';
}
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, d;
cin >> n>> d;
if(d==1)
{
vector<pair<ll,ll>> a(n);
for(int i=0; i < n; i++)
{
ll x;
cin >> x;
a[i] = {x, i};
}
sort(a.begin(), a.end(), greater<pair<ll,ll>>());
set<ll> indices;
map<ll,ll> nxtmx;
for (int i = 0; i < n; i++)
{
auto it = lower_bound(indices.begin(), indices.end(), a[i].second);
if(it == indices.end()) nxtmx[i] = -1;
else nxtmx[i] = *it;
indices.insert(a[i].second);
}
vector<ll> dp(n,1);
dp.back() = 1;
for (int i = n-2; i >= 0; i--)
{
if(nxtmx[i]!=-1) dp[i]+=dp[nxtmx[i]];
}
cout << *max_element(dp.begin(), dp.end()) << endl;
}
else{
vector<ll> a(n);
for(int i=0; i < n; i++) cin >> a[i];
vector<ll> dp(n,1);
dp.back() = 1;
for (int i = n-2; i >= 0; i--)
{
ll cur = 0;
for (int j=i+1; j < n; j++)
{
if(a[j] > a[i])
{
cur++;
dp[i] = max(dp[i], 1 + dp[j]);
if(cur == d)break;
}
else cur = 0;
}
}
cout << *max_element(dp.begin(), dp.end()) << endl;
}
}
# | 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... |