이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 7000 + 9;
const int INF = (int) 1e9;
int A[N], dp[N][N], pre[N], suff[N];
deque <int> dq[N];
map <int, int> id;
int main () {
int n;
cin >> n;
int D;
cin >> D;
set <int> s;
for (int i = 1; i <= n; i++) {
cin >> A[i];
s.insert (A[i]);
}
int c = 1;
for (auto u: s)
id[u] = c++;
for (int i = 1; i <= n; i++) {
A[i] = id[A[i]];
suff[i] = pre[i] = -INF;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
dp[i][j] = -INF;
pre[0] = suff[0] = -INF;
for (int i = 1; i <= n; i++) {
dp[i][A[i]] = max (1, pre[A[i] - 1] + 1);
for (int mx = A[i]; mx <= n; mx++) {
dp[i][mx] = max (dp[i][mx], suff[mx]);
//dp[i][mx] = max (dp[i][mx], pre[mx]);
while (dq[mx].size() && dp[dq[mx].back()][mx] < dp[i][mx])
dq[mx].pop_back();
dq[mx].push_back (i);
}
for (int mx = 1; mx <= n; mx++) {
while (dq[mx].size() && dq[mx].front() <= i - D)
dq[mx].pop_front();
if (dq[mx].size()) {
pre[mx] = suff[mx] = dp[dq[mx].front()][mx];
} else {
pre[mx] = suff[mx] = -INF;
}
}
for (int mx = 2; mx <= n; mx++)
pre[mx] = max (pre[mx], pre[mx - 1]);
//for (int mx = n - 1; mx >= 1; mx--)
//suff[mx] = max (suff[mx], suff[mx + 1]);
}
int res = 1;
for (int i = 1; i <= n; i++)
res = max (res, dp[n][i]);
cout << res << "\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... |