이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define i64 long long
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
const int INF = 1e9;
void Maximize(pair<int, int> &a, pair<int, int> b) {
if (a.first < b.first) a = b;
else if (a.first == b.first) a.second = min(a.second, b.second);
}
void Solve(void) {
int N, D; cin >> N >> D;
vector<int> a(N + 1);
vector<pair<int, int>> f(N + 1, mp(-INF, INF));
for (int i = 1; i <= N; i ++) cin >> a[i];
int ans = 0;
for (int st = 0; st <= N; st ++) {
f[st] = mp(0, -1);
for (int i = st + 1; i <= N; i ++) {
f[i] = mp(1, a[i]);
for (int j = i - 1; j >= max(st, i - D); j --) {
pair<int, int> cur = mp(f[j].first + (a[i] > f[j].second), max(a[i], f[j].second));
Maximize(f[i], cur);
}
// cout << i << " " << f[i].first << " " << f[i].second << "\n";
}
ans = max(ans, f[N].first);
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(10);
int Tests = 1; // cin >> Tests;
while (Tests --) {
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... |