Submission #645772

#TimeUsernameProblemLanguageResultExecution timeMemory
645772kith14Safety (NOI18_safety)C++17
4 / 100
1 ms724 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define db double #define pairll pair<ll,ll> #define lpairll pair<ll,pairll> #define repp(i,a,b) for (ll i = a; i <= b; i++) #define repz(i,a,b) for (ll i = a; i < b; i++) #define repm(i,a,b) for (ll i = a; i >= b; i--) #define fr first #define sc second #define x first #define y second #define mp make_pair #define pb push_back const ll N = 5e3+5, MOD = 1e9+7; ll tc = 1, n, m, ar[N], br[N], dp[2][N]; string s, s1, s2, ye = "YA", no = "TIDAK"; void input(){ cin >> n >> m; repp(i,1,n) cin >> ar[i]; } void solve(){ ll lm = 400; repp(i,0,lm){ dp[n%2][i] = abs(i-ar[n]); } repm(i,n-1,1){ ll cur = (i)%2, pre = (i+1)%2; repp(j,0,lm){ dp[cur][j] = 1e18; ll btl = max(0LL,j-m); repp(kk,btl,j+m){ dp[cur][j] = min(dp[cur][j],dp[pre][kk]+abs(ar[i]-j)); } } } ll ans = 1e18; repp(i,0,lm){ ans = min(ans,dp[1][i]); } cout << ans << endl; } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); //cin >> tc; while(tc--){ input(); solve(); } }
#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...