Submission #961622

#TimeUsernameProblemLanguageResultExecution timeMemory
961622vjudge1Safety (NOI18_safety)C++17
4 / 100
3207 ms262144 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ent "\n" const int maxn = 5e3 + 100; const ll INF = (ll)1e18 + 100; const int inf = 1e9 + 100; const int MOD = 1e9 + 7; const int maxl = 14; int n, h; int a[maxn]; ll dp[maxn][maxn]; void test(){ cin >> n >> h; for(int i = 1; i <= n ;i++){ cin >> a[i]; } for(int x = 0; x <= 400; x++){ dp[1][x] = abs(x - a[1]); } for(int i = 2; i <= n; i++){ deque<ll> d; for(int x = 0, l = 0, r = -1; x <= 400; x++){ while(abs(r - x + 1) <= h){ r++; while(d.size() && d.back() > dp[i-1][r]){ d.pop_back(); } d.push_back(dp[i-1][r]); } while(abs(l - x) > h){ if(d.front() == dp[i-1][l]){ d.pop_front(); } l++; } dp[i][x] = d.front() + abs(x - a[i]); } } sort(dp[n], dp[n] + 400 + 1); cout << dp[n][0]; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1; while(t--) test(); cout << ent; }
#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...