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 <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#warning That's not the baby, that's my baby
#define debug(x) #x << " = " << x << '\n'
typedef long long ll;
int smart(int n, int D, int T, std::vector<int> a) {
std::vector<int> v;
int start = 0;
int answer = n;
bool atStart = true;
for (int i = 1; i <= n; i++) {
int x = a[i - 1];
start = std::min(start + 1, x);
if (x > T) {
if (atStart) {
answer--;
continue;
}
if (start > T) {
v.back()++;
} else {
v.push_back(1);
}
start = T + 1;
} else {
atStart = false;
}
}
std::sort(v.begin(), v.end());
std::reverse(v.begin(), v.end());
for (int i = 0; i < D && i < (int) v.size(); i++) {
answer -= v[i];
}
return answer;
}
int dumbDP(int n, int D, int T, std::vector<int> a) {
std::vector<std::vector<int>> dp(n + 1, std::vector<int>(D + 1, -n));
a.insert(a.begin(), 0);
std::vector<int> nxtT(n + 2, n + 1), nxt(n + 1, n + 1);
nxtT[n] = n + 1;
for (int i = 1; i <= n; i++) {
a[i] -= i;
}
for (int i = 1; i <= n; i++) {
int j = i + 1;
while (j <= n && a[j] + j <= T) {
j++;
}
nxtT[i] = j;
j = i + 1;
int mini = std::min(a[i], a[i + 1]);
while (j <= n && j + mini > T) {
j++;
}
if (j != i + 1) {
nxt[i] = j - 1;
}
}
for (int i = 1; i <= n; i++) {
if (a[i] + i > T) {
dp[i][0] = std::max(dp[i][0], 1);
for (int k = 0; k <= D; k++) {
if (k < D && nxtT[i] <= n) {
dp[nxtT[i]][k + 1] = std::max(dp[nxtT[i]][k + 1], 1 + dp[i][k]);
}
if (nxt[i] <= n) {
dp[nxt[i]][k] = std::max(dp[nxt[i]][k], 1 + dp[i][k]);
}
}
}
}
int maxi = 0;
for (int i = 1; i <= n; i++) {
for (int k = 0; k <= D; k++) {
maxi = std::max(maxi, dp[i][k]);
// if (dp[i][k] == 2) {
// std::cout << " ? " << i << ' ' << k << '\n';
// }
}
}
return n - maxi;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int n, D, T;
std::cin >> n >> D >> T;
std::vector<int> a(n);
for (auto &x : a) {
std::cin >> x;
}
std::cout << dumbDP(n, D, T, a);
return 0;
}
Compilation message (stderr)
prison.cpp:5:2: warning: #warning That's not the baby, that's my baby [-Wcpp]
5 | #warning That's not the baby, that's my baby
| ^~~~~~~
# | 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... |