제출 #1267258

#제출 시각아이디문제언어결과실행 시간메모리
1267258madamadam3Stove (JOI18_stove)C++20
20 / 100
1006 ms452 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {    
    cin.tie(0)->sync_with_stdio(0);

    int n, k; cin >> n >> k;
    vector<int> times(n); 

    for (int i = 0; i < n; i++) {
        cin >> times[i]; 
        times[i]--;
    }

    int ans = 21;
    // int best = 0;

    for (int mask = 0; mask < (1 << 20); mask++) {
        int matches = 0, total_on = 0;
        for (int i = 0; i < 20; i++) {
            if (!(mask & (1 << i))) continue;
            total_on++;

            if (i == 0) matches++;
            if (i > 0 && !(mask & (1 << (i-1)))) matches++;
        }

        if (matches > k) continue;

        bool can = true; for (int i = 0; i < n; i++) can = can && (mask & (1 << times[i]));
        if (can && total_on < ans) {
            ans = total_on;
            // best = mask;
        }
    }

    // for (int i = 0; i < 20; i++) cerr << (best & (1 << i)) ? 1 : 0;
    // cerr << "\n";

    cout << ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...