제출 #1267816

#제출 시각아이디문제언어결과실행 시간메모리
1267816minhmc2019Rabbit Carrot (LMIO19_triusis)C++20
0 / 100
796 ms456 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    int best = 0; // số cột giữ lại nhiều nhất
    // Duyệt tất cả tập con bằng bitmask
    for (int mask = 1; mask < (1 << N); mask++) {
        vector<int> sub; 
        for (int i = 0; i < N; i++) {
            if (mask & (1 << i)) sub.push_back(a[i]); // giữ lại cột i
        }

        // Kiểm tra tập con này có hợp lệ không
        bool ok = true;
        int prevHeight = 0; // thỏ bắt đầu từ 0
        for (int h : sub) {
            if (h > prevHeight + M) { // không nhảy lên được
                ok = false;
                break;
            }
            prevHeight = h;
        }

        if (ok) best = max(best, (int)sub.size());
    }

    int ans = N - best; // số cột phải chỉnh sửa
    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...