This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
typedef vector<pl> vp;
#define nl "\n"
#define fr first
#define sc second
#define pb push_back
#define all(x) x.begin(), x.end()
#define fur(i, a, b) for(ll i = a; i <= b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= b; --i)
#define pv(x) for(auto k : x){cout << k << " ";} cout << nl
const ll inf = 1e17;
void solve(){
ll n, k;
cin >> n >> k;
vl a(n);
fur(i, 0, n-1) cin >> a[i];
vl b = a;
sort(all(b));
ll ans = inf;
fur(i, 0, (1<<n)-1){
ll bm = i;
set<ll> tof;
vl seq;
fur(j, 0, n-1){
if ((1<<j) & i){
tof.insert(j);
}else{
seq.pb(a[j]);
}
}
for(auto u: tof)
seq.pb(a[u]);
// seq = {2, 1, 7, 5, 10, 16};
bool val = 1;
vl tmp;
ll t = 0;
ruf(x, n-1, 0){
t++;
tmp.pb(seq[x]);
if (t+1 > k){
sort(all(tmp));
//pv(tmp);
fur(m, 0, k-1){
if (tmp[m] != b[m+x]){
val = 0;
break;
}
}
t = 0;
tmp.clear();
}
}
if (val){
//pv(seq);
//cout << tof.size() << nl;
ans = min(ans, (ll)tof.size());
}
}
cout << ans << nl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
ll t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
Compilation message (stderr)
studentsko.cpp: In function 'void solve()':
studentsko.cpp:32:12: warning: unused variable 'bm' [-Wunused-variable]
32 | ll bm = i;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |