제출 #892407

#제출 시각아이디문제언어결과실행 시간메모리
892407MinaRagy06Rabbit Carrot (LMIO19_triusis)C++17
63 / 100
1039 ms1880 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 + i;
        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);
            }
        }
        for (int j = i; j < n; j++) {
            if (j == n - 1 || a[i] - i * m >= a[j + 1] - j * m || a[j + 1] - j * m <= a[i] - i * m + m) {
                dp[i] = min(dp[i], dp[j + 1] + j);
            }
        }
        dp[i] -= i;
        if (a[i] >= a[i + 1] || a[i + 1] - a[i] <= m) {
            dp[i] = min(dp[i], dp[i + 1]);
        }
    }
    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...