Submission #141514

#TimeUsernameProblemLanguageResultExecution timeMemory
141514meatrowSafety (NOI18_safety)C++17
13 / 100
62 ms4344 KiB
//#pragma GCC optimize("O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native") //#pragma GCC optimize ("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e3 + 5; int s[N]; ll dp[N][N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, h; cin >> n >> h; for (int i = 0; i < n; i++) { cin >> s[i]; } for (int j = 0; j < N; j++) { dp[0][j] = abs(s[0] - j); } for (int i = 1; i < n; i++) { int l = 0, r = 0; multiset<ll> q; for (int j = 0; j < N; j++) { while (r < N && r <= j + h) { q.insert(dp[i - 1][r]); r++; } while (l < N && l < j - h) { q.erase(q.find(dp[i - 1][l])); l++; } dp[i][j] = abs(s[i] - j) + *q.begin(); } } ll ans = LLONG_MAX; for (int i = 0; i < N; i++) { ans = min(ans, dp[n - 1][i]); } cout << ans; return 0; }
#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...