제출 #892405

#제출 시각아이디문제언어결과실행 시간메모리
892405MinaRagy06Rabbit Carrot (LMIO19_triusis)C++17
63 / 100
1058 ms1884 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; int a[n + 1]; a[0] = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; } n++; int dp[n + 1]; dp[n - 1] = dp[n] = 0; for (int i = n - 2; i >= 0; i--) { dp[i] = 1e9; if (a[i] >= a[i + 1] || a[i + 1] - a[i] <= m) { dp[i] = dp[i + 1]; } for (int j = i + 1; j < n; j++) { if (j == n - 1 || a[j + 1] <= a[i] + 2 * m) { dp[i] = min(dp[i], dp[j + 1] + j - i); } } for (int j = i; j < n; j++) { if (j == n - 1 || a[i] - i * m >= a[j + 1] - j * m || a[j + 1] - (a[i] + j * m - i * m) <= m) { dp[i] = min(dp[i], dp[j + 1] + j - i); } } } cout << dp[0] << '\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...