제출 #895133

#제출 시각아이디문제언어결과실행 시간메모리
895133d4xnRabbit Carrot (LMIO19_triusis)C++17
35 / 100
1040 ms21580 KiB
#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]; vector<int> suf, dp[2]; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; a[0] = 0; mx = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; mx = max(mx, a[i]); } dp[0].clear(); dp[0].resize(1); dp[0][0] = 0; for (int i = 1; i <= n; i++) { int x = min(mx+1, m*(i-1) + 1); suf.clear(); suf.resize(x); for (int j = x-1; j >= 0; j--) { suf[j] = min(dp[(i-1)%2][j], (j+1 < x ? suf[j+1] : inf)); } int y = min(mx+1, m*i + 1); dp[i%2].clear(); dp[i%2].resize(y); for (int j = 0; j < y; j++) { dp[i%2][j] = suf[max(0, j-m)] + (j != a[i]); } } int ans = inf; for (int i = 0; i <= min(mx, n*m); i++) { ans = min(ans, dp[n%2][i]); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...