Submission #991922

#TimeUsernameProblemLanguageResultExecution timeMemory
991922overwatch9Safety (NOI18_safety)C++17
4 / 100
2058 ms262144 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; int n, h; vector <ll> s; vector <vector <ll>> dp; ll solve(int i, int prev) { if (i > n) return 0; if (dp[i][prev] != -1) return dp[i][prev]; ll ans = 1e10; for (int j = max(0, prev - h); j <= min(prev + h, 800); j++) ans = min(ans, solve(i+1, j) + abs(j - s[i])); dp[i][prev] = ans; return ans; } int main() { cin >> n >> h; s = vector <ll> (n+1); for (int i = 1; i <= n; i++) cin >> s[i]; int maxs = *max_element(s.begin(), s.end()); dp = vector <vector <ll>> (n+1, vector <ll> (800 + 1, -1)); ll ans = 1e10; for (int i = 0; i <= 800; i++) { dp = vector <vector <ll>> (n+1, vector <ll> (800 + 1, -1)); ans = min(ans, solve(1, i)); } cout << ans << '\n'; }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:26:9: warning: unused variable 'maxs' [-Wunused-variable]
   26 |     int maxs = *max_element(s.begin(), s.end());
      |         ^~~~
#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...