이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
int main() {
int n, d;
cin >> n >> d;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
do {
// compression
vector<int> dd = v;
sort(dd.begin(), dd.end());
dd.resize(unique(dd.begin(), dd.end()) - dd.begin());
for (int i = 0; i < n; i++) {
v[i] = lower_bound(dd.begin(), dd.end(), v[i]) - dd.begin();
}
} while (false);
int mx = *max_element(v.begin(), v.end());
// cout << mx << endl;
// cout << "V: ";
// for (auto x : v) cout << x << " ";
// cout << endl;
vector<vector<int>> dp(n, vector<int>(mx + 1, 0));
vector<multiset<int>> cmax(mx + 1);
for (int i = 0; i < n; i++) {
// cout << "i=" << i << endl;
int prev, cur = 0;
for (int j = 0; j <= mx; j++) {
prev = cur;
if (cmax[j].size()) {
// cout << " j=" << j << ' ' << *cmax[j].rbegin() << endl;
cur = max(cur, *cmax[j].rbegin());
}
if (j < v[i]) continue;
int candidate = max(cur, j ? dp[i][j - 1] : 0);
if (v[i] == j) candidate = max(candidate, j ? prev + 1 : 1);
dp[i][j] = candidate;
}
// cout << endl;
if (i >= d) {
for (int j = 0; j <= mx; j++) {
cmax[j].erase(cmax[j].find(dp[i - d][j]));
}
}
for (int j = 0; j <= mx; j++) {
cmax[j].insert(dp[i][j]);
}
}
// for (auto x : dp) {
// for (auto y : x) cout << y << " ";
// cout << endl;
// }
cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << 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... |