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;
#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif
const int N = 7005;
int a[N];
int la[N][N];
vector<int> v[N];
int n, d;
int dp[N][N];
int bt (int id, int mx) {
if (id == n) return 0;
int& ret = dp[id][mx];
if (ret != -1) {
return ret;
}
if (a[id] <= mx) {
return ret = bt(id + 1, mx);
}
if (id - la[mx][id] > d) {
return 0;
}
ret = max(bt(id + 1, mx), bt(id + 1, a[id]) + 1);
return ret;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> d;
vector<int> b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
b[i] = a[i];
}
sort(b.begin(), b.end());
b.resize(unique(b.begin(), b.end()) - b.begin());
for (int i = 0; i < n; ++i) {
a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin() + 1;
}
for (int i = 0; i < n; ++i) {
la[0][i] = i;
for (int j = 1; j < n; ++j) {
if (j >= a[i]) {
la[j][i] = i;
} else {
la[j][i] = (i ? la[j][i - 1] : 0);
}
}
}
memset(dp, -1, sizeof dp);
for (int i = 0; i < n; ++i) {
v[a[i]].push_back(i);
}
cout << bt(0, 0) << '\n';
return 0;
}
# | 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... |