Submission #799445

#TimeUsernameProblemLanguageResultExecution timeMemory
799445antonSafety (NOI18_safety)C++17
13 / 100
213 ms2640 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int INF = 1e18; const int MAX_N = 600; const int MAX_H = 600; int n, h; int A[MAX_N]; int dp[MAX_N][MAX_H]; signed main(){ cin>>n>>h; for(int i = 0; i<n; i++){ cin>>A[i]; } for(int i = n; i>=0; i--){ for(int j = 0; j<MAX_H; j++){ if(i==n){ dp[i][j] = 0; } else{ dp[i][j] = INF; for(int k = max(0LL,j-h); k<=min(MAX_H-1,j+h); k++){ dp[i][j] = min(dp[i][j], dp[i+1][k] + abs(k-A[i])); } } } } int res= INF; for(int i = 0; i<MAX_H; i++){ res= min(res, dp[0][i]); } cout<<res<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...