Submission #124130

#TimeUsernameProblemLanguageResultExecution timeMemory
124130mechfrog88Safety (NOI18_safety)C++14
13 / 100
2063 ms18680 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long ll; typedef long double ld; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,d; cin >> n >> d; vector <ll> arr(n+1); ll maxi = 0; for (int z=1;z<=n;z++){ cin >> arr[z]; maxi = max(maxi,arr[z]); } vector <vector<ll>> dp(n+1,vector<ll>(maxi+1,0)); for (ll z=1;z<=n;z++){ for (ll h=0;h<=maxi;h++){ ll mini = LLONG_MAX; for (int x=max(ll(0),h-d);x<=min(maxi,h+d);x++){ mini = min(mini,dp[z-1][x]); } dp[z][h] = mini+abs(arr[z]-h); } } ll mini = LLONG_MAX; for(ll z=0;z<=maxi;z++){ mini = min(dp[n][z],mini); } cout << mini << 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...