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;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
vi a, b;
int n, k;
map<int, int> m;
int dp[9000];
int pos[9000][9000];
int rec(int x){
int ans=1;
if(dp[x]!=-1) return dp[x];
FOR(i,n){
if(x+i+1>=n) break;
if(a[x+i+1]<=a[x]) break;
if(pos[x][x+i+1]) ans = max(ans, 1 + rec(x+i+1));
}
//assert(ans>=dp[x]);
dp[x] = max(dp[x], ans);
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>k;
//FOR(i,n) FOR(j,n) dp[i][j] = -1;
FOR(i,n+1) dp[i] = -1;
a.resize(n);
FOR(i,n) cin>>a[i];
int cnt=0;
set<int> all;
FOR(i,n) all.insert(a[i]);
FOA(v, all) m[v] = ++cnt;
FOR(i,n) a[i] = m[a[i]];
FOR(i,n){
int cnt=0;
FORi(j,i,n){
if(a[j]>a[i]) cnt++;
else cnt=0;
if(cnt<=k && a[j]>a[i]) pos[i][j] = true;
else if(cnt>=k) break;
}
}
/*
FOR(i,n){
cout<<i<<": ";
FORi(j,i+1,n) if(pos[i][j]) cout<<j<<" ";
cout<<endl;
}*/
//FOR(i,n) cout<<a[i]<<" ";
//cout<<endl;
int maxa = 0;
//FOR(i,n) cout<<rec(i,a[i])<<" ";
//cout<<endl;
FOR(i,n){
maxa = max(maxa, rec(i));
}
cout<<maxa<<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... |