# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
963699 | guechotjrhh | Safety (NOI18_safety) | C++14 | 174 ms | 2216 KiB |
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<stdio.h>
#include<vector>
#pragma warning (disable:4996)
using namespace std;
#define ll long long
ll ab(ll n) { return n > 0 ? n : -n; }
long long func(int n, int h, vector<int> s) {
vector<ll> dp(501,0);
for (int i = 0; i < n; i++) {
vector<ll> ndp(501);
for (int j = 0; j <= 500; j++) {
ndp[j] = ab(j - s[i]);
ll mn = 1e18;
for (int k = max(0, j - h); k <= min(500, j + h); k++) mn = min(mn, dp[k]);
ndp[j] += mn;
}
dp = ndp;
}
ll mn = 1e18;
for (int i = 0; i <= 500; i++) mn = min(mn, dp[i]);
return mn;
}
int main() {
int N, H;
scanf("%d%d", &N, &H);
vector<int> S(N);
for (int i = 0; i < N; i++) scanf("%d", &S[i]);
long long ans = func(N, H, move(S));
printf("%d\n", ans);
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |