Submission #200194

#TimeUsernameProblemLanguageResultExecution timeMemory
200194wilwxkSafety (NOI18_safety)C++14
35 / 100
566 ms196344 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(int i, int j, int l) { while(dq.size() && dq.back().second < l) dq.pop_back(); if(i >= MAXN || j >= MAXN) return; ll val = dp[i][j]; while(dq.size() && dq.front().first >= val) dq.pop_front(); dq.push_front({val, j}); } 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++) { for(int j = 0; j < min(x, MAXN); j++) update(i-1, j, -1); for(int j = 0; j < MAXN; j++) { update(i-1, j+x, j-x); ll cost = abs(j-v[i]); cost += query(); 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...