Submission #1361298

#TimeUsernameProblemLanguageResultExecution timeMemory
1361298mrcat2011Stove (JOI18_stove)C++20
20 / 100
82 ms460 KiB
#include <bits/stdc++.h>
using namespace std;

typedef int64_t ll;


ll n, k;

ll Cnt(vector<ll> v) {
    map<ll, ll> mp;

    mp[0]++;

    ll cur_sum = 0;
    ll cnt = 0;
    for (ll i = 0; i < n; ++i) {
        cur_sum += v[i];

        ll rem = ((cur_sum % n) + n) % n;
        cnt += mp[rem];

        mp[rem]++;
    }
    return cnt;
}


void solve () {
    cin >> n >> k;
    vector<ll> v(n);
    for (ll& x : v) cin >> x;

    ll t = 20;

    //0 0 0 0 0 0......
    //1 1 0  1  0  1 
    //3
    //

    ll ans = LLONG_MAX;
    for (ll i = 0; i < (1LL << t); ++i) {
        vector<bool> mp(21, 0);
        ll true_cnt = 0;
        bool open = false;
        ll cnt = 0;
        for (ll j = 0; j < t; ++j) {
            if (i & (1LL << j)) {
                mp[j + 1] = true;
                true_cnt++;
                if (!open) {
                    cnt++;
                }
                open = true;
            } else {
                open = false;
                mp[j + 1] = false;
            }
        }

        if (cnt > k) continue; 
        //20
        //1 1 0 1 

        bool tf = true;
        for (ll j = 0; j < n; ++j) {
            if (mp[v[j]]) {
                continue;   
            } else {
                tf = false; break;
            }
        }

        if (tf) {
            if (ans > true_cnt) {
                ans = true_cnt;
                //cout << endl;
            }
        }
    }

    cout << ans << endl;
}   

int main (int argc, char* argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1; //cin >> t;
    while (t --) {
        solve();
    }
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...