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>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 4005;
int n, d, T, t[MN], cnt[MN][MN], dp[MN][MN];
void solve(int j, int l, int r, int p1, int p2) {
int mid = (l + r) >> 1, opt = n + 1, num = 0, mn = 0x3f3f3f3f;
for (int i = max(mid, p1); i <= p2; i++) {
if (min(mn, t[i]) <= T) num++;
mn = min(mn, t[i]) + 1;
if (dp[mid][j] >= dp[i + 1][j - 1] + num) {
dp[mid][j] = dp[i + 1][j - 1] + num;
opt = i;
}
}
if (l == r) return;
solve(j, mid + 1, r, opt, p2);
solve(j, l, mid, p1, opt);
}
int32_t main() {
boost();
cin >> n >> d >> T;
for (int i = 1; i <= n; i++) cin >> t[i];
for (int i = 1; i <= n; i++) {
int num = 0, mn = 0x3f3f3f3f;
for (int j = i; j <= n; j++) {
if (min(mn, t[j]) <= T) num++;
cnt[i][j] = num;
mn = min(mn, t[j]) + 1;
}
}
memset(dp, 0x3f, sizeof(dp));
dp[n + 1][0] = 0;
for (int i = 1; i <= d + 1; i++) solve(i, 1, n, 1, n);
printf("%lld\n", dp[1][d + 1]);
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... |