| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1357717 | coin_ | Safety (NOI18_safety) | C++20 | 2095 ms | 327680 KiB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e18;
signed main(){
int n, h;
cin >> n >> h;
int maxH = 5005;
vector<vector<int>> dp(n+5, vector<int>(maxH, inf));
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int hi = 0; hi < maxH; hi++){
dp[0][hi] = abs(a[0] - hi);
}
h = min(h, maxH);
for (int i = 1; i < n; i++){
for (int hi = 0; hi < maxH; hi++){
int gain = inf;
for (int j = max(0LL, hi - h); j <= min(hi + h, maxH-1); j++){
gain = min(dp[i-1][j], gain);
}
dp[i][hi] = min(dp[i][hi], abs(a[i] - hi) + gain);
}
}
int ans = inf;
for (int i = 0; i < maxH; i++){
ans = min(ans, dp[n-1][i]);
}
cout << ans;
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
