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 fi first
#define se second
#define all(x) x.begin(), x.end()
#define getbit(x) (((x) >> (i)) & 1)
#define TASK ""
using namespace std;
template <typename T1, typename T2> bool maxi(T1 &a, T2 b) {
if (a < b) a = b; else return false; return true;
}
template <typename T1, typename T2> bool mini(T1 &a, T2 b) {
if (a > b) a = b; else return false; return true;
}
const long long inf = 1e18;
const int mod = 1e9 + 7;
const int N = 3e5 + 5;
int n;
int d;
int a[N];
namespace subtask2 {
int dp[405][405];
vector <int> value;
void solve() {
for (int i = 1; i <= n; ++i) value.push_back(a[i]);
sort(all(value));
value.erase(unique(all(value)), value.end());
int m = (int) value.size();
for (int i = 1; i <= n; ++i) {
a[i] = lower_bound(all(value), a[i]) - value.begin() + 1;
}
memset(dp, -0x3f, sizeof dp);
for (int i = 1; i <= n; ++i) dp[i][a[i]] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = i - 1; j >= max(i - d, 1); --j) {
for (int mx = 1; mx <= m; ++mx) {
maxi(dp[i][max(mx, a[i])], dp[j][mx] + (mx < a[i]));
}
}
}
cout << *max_element(dp[n] + 1, dp[n] + m + 1);
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen(TASK".inp", "r", stdin);
//freopen(TASK".out", "w", stdout);
cin >> n >> d;
for (int i = 1; i <= n; ++i) cin >> a[i];
if (n <= 400) subtask2::solve();
}
# | 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... |