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'
using ll = long long;
const ll INF = 1e18;
const int mod = 1e9 + 7;
int toHash(std::vector<ll> x) {
int ret = 0;
for (int i = 0; i < (int) x.size(); i++) {
x[i] %= mod;
ret = ((ll) ret * 23 + x[i]) % mod;
}
return ret;
}
int solve(int n, int k, int *A) {
std::vector<ll> dp(n + 1, INF);
std::vector<int> a(n + 1, 0);
for (int i = 0; i < n; i++) {
a[i + 1] = A[i];
}
dp[0] = 0;
for (int i = 1; i <= n; i++) {
int maxi = 0;
for (int j = i; j > 0 && j > i - k; j--) {
maxi = std::max(maxi, a[j]);
dp[i] = std::min(dp[i], dp[j - 1] + maxi);
}
}
dp.erase(dp.begin());
return toHash(dp);
}
#ifdef LOCAL
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, k;
std::cin >> n >> k;
int *a = new int[n];
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
std::cout << solve(n, k, a);
return 0;
}
#endif
Compilation message (stderr)
peru.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... |