이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA
const int INF = INT_MAX;
void solve() {
int N, D; cin >> N >> D;
vector<int> A(N);
for (int &x : A) cin >> x;
vector<int> dp(N, 1);
for (int i = N-1; i >= 0; --i) {
for (int j = i+1, flag = 0; (j <= i+D or !flag) and j < N; ++j) {
if (A[j] > A[i]) chmax(dp[i], dp[j] + (j <= i+D)), flag = 1;
if (A[j] == A[i]) chmax(dp[i], dp[j]), flag = 1;
}
// debug(i, dp[i]);
}
cout << *max_element(ALL(dp)) << "\n";
// vector dp(2, vector<int>(N, 0));
// for (int pick = 1; pick <= N+1; ++pick) {
// fill(ALL(dp[pick&1]), INF);
// if (pick == 1) dp[pick&1][0] = A[0];
// for (int i = 1; i < N; ++i) {
// for (int j = i-1; j >= max(i-D, int(0)); --j) {
// chmin(dp[pick&1][i], (dp[(pick^1)&1][j] >= A[i] ? dp[pick&1][j] : A[i]));
// }
// // debug(pick, i, dp[pick&1][i]);
// }
// if (dp[pick&1][N-1] == INF) { cout << pick - 1 << "\n"; break; }
// }
}
int32_t main() {
fastIO();
int t = 1; // cin >> t;
for (int _ = 1; _ <= t; ++_) {
solve();
}
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
using float80 = long double;
#define double float80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
#ifdef local
#define fastIO() void()
#define debug(...) \
fprintf(stderr, "\u001b[33m"), \
fprintf(stderr, "At [%s], line %d: (%s) = ", __FUNCTION__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), \
fprintf(stderr, "\u001b[0m")
template <typename T> void _do(T &&_t) { cerr << _t << "\n"; }
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) { cerr << _t << ", ", _do(_u...); }
#else
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)
#define debug(...) void()
#endif
template <typename T, typename U> bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; }
template <typename T, typename U> bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; }
#endif
# | 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... |