Submission #200189

#TimeUsernameProblemLanguageResultExecution timeMemory
200189wilwxkSafety (NOI18_safety)C++14
4 / 100
1711 ms1144 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 5e3+5; int v[MAXN]; ll dp[MAXN][MAXN]; deque<pair<ll, int> > dq; int n, x; void update(ll val, int id, int l, int r) { if(id > MAXN) return; // printf("upd %lld %d %d %d\n", val, id, l, r); while(dq.size() && dq.back().second < l) dq.pop_back(); while(dq.size() && dq.front().first >= val) dq.pop_front(); dq.push_front({val, id}); } ll query() { return dq.back().first; } int main() { scanf("%d %d", &n, &x); for(int i = 1; i <= n; i++) scanf("%d", &v[i]); for(int i = 1; i <= n; i++) { int l = -x; int r = x; for(int j = 0; j <= x; j++) update(dp[i-1][j], j, l, r); for(int j = 0; j < MAXN; j++) { while(j+x > r) l++, r++, update(dp[i-1][r], r, l, r); ll cost = abs(j-v[i]); cost += query(); // printf("%d %d >> %lld\n", i, j, cost); dp[i][j] = cost; } while(dq.size()) dq.pop_back(); } ll ans = 1e18; for(int i = 0; i < MAXN; i++) ans = min(ans, dp[n][i]); printf("%lld\n", ans); }

Compilation message (stderr)

safety.cpp: In function 'int main()':
safety.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &x);
  ~~~~~^~~~~~~~~~~~~~~~~
safety.cpp:25:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%d", &v[i]);
                              ~~~~~^~~~~~~~~~~~~
#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...