Submission #1247597

#TimeUsernameProblemLanguageResultExecution timeMemory
1247597cuongngooRabbit Carrot (LMIO19_triusis)C++20
0 / 100
23 ms328 KiB
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 2e5 + 5, inf = 1e18;

int n, m;
int h[N], f[N];

int32_t main() {
  cin.tie(0) -> sync_with_stdio(0);

  #define task "RABBIT CARROT"

  if (fopen ("task.inp", "r")) {
    freopen ("task.inp", "r", stdin);
    freopen ("task.out", "w", stdout);
  }

  if (fopen (task".inp", "r")) {
    freopen (task".inp", "r", stdin);
    freopen (task".out", "w", stdout);
  }

  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> h[i];

  for (int i = 1; i <= n; ++i) f[i] = inf;
  if (h[1] > m) f[1] = 1, h[1] = m;
  else f[1] = 0;

  for (int i = 2; i <= n; ++i)
    for (int j = i - 1; j >= 1; --j)
      if (h[j] + m >= h[j + 1] - m * (i - j - 1))
        f[i] = min(f[i], f[j] + (i - j - 1));

  for (int j = n - 1; j >= 1; --j)
    if (h[j] + m >= h[j + 1] - m * (n - j))
      f[n] = min(f[n], f[j] + (n - j));

  cout << f[n];
}

Compilation message (stderr)

triusis.cpp: In function 'int32_t main()':
triusis.cpp:17:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     freopen ("task.inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:18:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen ("task.out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:22:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen (task".inp", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:23:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen (task".out", "w", stdout);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...