Submission #666564

#TimeUsernameProblemLanguageResultExecution timeMemory
666564I_love_Chou_GiangRabbit Carrot (LMIO19_triusis)C++14
35 / 100
179 ms98428 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define vt vector #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define R_EP(i, a, b, s) for (int i = (a); (s) > 0 ? i < (b) : i > (b); i += (s)) #define R_EP1(e) R_EP(i, 0, e, 1) #define R_EP2(i, e) R_EP(i, 0, e, 1) #define R_EP3(i, b, e) R_EP(i, b, e, 1) #define R_EP4(i, b, e, s) R_EP(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define R_EPC(...) GET5(__VA_ARGS__, R_EP4, R_EP3, R_EP2, R_EP1) #define rep(...) R_EPC(__VA_ARGS__)(__VA_ARGS__) #define trav(x, a) for (auto x : a) template<typename T> inline bool umax(T&x, const T& y) { if (x >= y) return false; x = y; return true; } template<typename T> inline bool umin(T&x, const T& y) { if (x <= y) return false; x = y; return true; } const int MOD = int(1e9) + 7, naxm = 5000, INF = int(1e9); int N, M, a[naxm + 5], dp[naxm + 5][naxm + 5], suffix[naxm + 5]; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); cin >> N >> M; rep(i, 1, N + 1) cin >> a[i]; rep(i, N + 1) { rep(j, 5001) dp[i][j] = INF; } dp[0][0] = 0; rep(i, 1, N + 1) { rep(j, 5002) suffix[j] = INF; rep(j, 5000, -1, -1) suffix[j] = min(suffix[j + 1], dp[i - 1][j]); rep(j, 5001) umin(dp[i][j], suffix[max(0, j - M)] + (j != a[i])); } int ans = INF; rep(i, 5001) umin(ans, dp[N][i]); cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...