#include "bits/stdc++.h"
using namespace std;
//\\ PRINCIPAL \\//
#define oo 1e18
#define endl "\n"
#define mod 1000000007
#define int long long
#define tle while(1){;}
#define ios ios_base::sync_with_stdio(0); cin.tie(0),cout.tie(0)
//\\ BITS \\//
#define bits_1 __builtin_popcount
//\\ STL \\//
#define fr first
#define sc second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define lb(x,y) lower_bound(x.begin(),x.end(),y)-x.begin()
#define ub(x,y) upper_bound(x.begin(),x.end(),y)-x.begin()
/*MST
#include "bits/extc++.h"
typedef tree<pair<int,int>,null_type,less_equal<>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
using namespace __gnu_pbds;
*/
int32_t main() {
ios;
int n,k;
cin >> n >> k;
int N = 20;
vector<int>v(n);
for(int&i : v)
{
cin >> i;
}
for(int i = 0; i < n; i++)
{
v[i]--;
}
int minn = oo;
for(int i = 0; i < (1 << N); i++)
{
bool f = 0;
int c = 0;
if(i & (1 << 0)) {
c++;
}
for(int j = 0; j < N; j++)
{
if(j > 0) {
if(!(i & (1 << (j - 1))) && (i & (1 << j))) {
c++;
}
}
}
for(int j = 0; j < n; j++)
{
if(!(i & (1 << v[j]))) {
f = 1;
break;
}
}
//cout << i << " " << c << " " << f << endl;
if(!f && c <= k) {
int ans = bits_1(i);
minn = min(minn,ans);
}
}
cout << minn << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |