Submission #895146

# Submission time Handle Problem Language Result Execution time Memory
895146 2023-12-29T13:28:52 Z d4xn Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
0 ms 348 KB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5+1, inf = INT_MAX;

int n, m, mx, a[N];
map<int, int> dp[2];

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m;
  a[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i%2].clear();

    int mx = 0;
    for (auto& [x, y] : dp[(i-1)%2]) {
      if (mx < a[i] && y+m >= a[i]) {
        auto it = dp[i%2].find(x);
        if (it == dp[i%2].end()) dp[i%2][x] = a[i];

        it->second = max(it->second, a[i]);

        mx = a[i];
      }

      if (mx < y+m) {
        auto it = dp[i%2].find(x+1);
        if (it == dp[i%2].end()) dp[i%2][x+1] = y+m;
        
        it->second = max(it->second, y+m);

        mx = y+m;
      }
    }
  }

  cout << dp[n%2].begin()->first << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -