이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=3e5+7;
ll n,m,k;
ll a[N];
ll dp[N];
int ri[N];
void precalc() {
}
int main() {
precalc();
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a[i];
}
if(k==1){
stack<int>st;
ll ans=0;
for(int i=n-1;i>=0;i--){
while(!st.empty()&&st.top()<=a[i]){
st.pop();
}
st.push(a[i]);
ans=max(ans,(ll)st.size());
}
cout<<ans<<endl;
return 0;
}
for(int i=0;i<n;i++){
ri[i]=i;
for(int j=i+1;j<min(n,ri[i]+k+1);j++){
if(a[j]<=a[i]){
ri[i]=j;
}
}
//cout<<ri[i]<<" ";
}
//cout<<endl;
ll ans=0;
for(int i=0;i<n;i++){
dp[i]=1;
for(int j=0;j<i;j++){
if(a[i]>a[j]&&ri[j]>=i-k){
dp[i]=max(dp[i],dp[j]+1);
}
}
if(ri[i]==n-1){
ans=max(ans,dp[i]);
}
//cout<<dp[i]<<" ";
}
cout<<ans<<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... |