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>
using namespace std;
typedef long long ll;
typedef pair<int,ll> ii;
const int MAX_N=3e5+10;
vector<ll> x;
int n,d;
map<ii,int> dp;
int report(int id,ll ma){
if(dp.find(ii(id,ma))!=dp.end())
return dp[ii(id,ma)];
if(id==n) return 0;
int r;
if(id==0) r=n;
else r=min(n,id+d);
int ans=0;
for(int i=id+1;i<=r;i++){
ll nma=max(ma,x[i]);
bool sw=(x[i]>ma);
ans=max(ans,report(i,nma)+sw);
}
return dp[ii(id,ma)]=ans;
}
int main(){
cin>>n>>d;
x.push_back(-1);
for(int i=0;i<n;i++){
ll a; cin>>a;
x.push_back(a);
}
cout<<report(0,-1)<<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... |