# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1215811 | szz0li | Arranging Shoes (IOI19_shoes) | C++20 | 0 ms | 0 KiB |
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
long long count_swaps(vector<int> s) {
int ans=INT_MAX/2;
int n=s.size()/2;
vector<int> perm;
for(int i=0;i<n*2;i++){
if(s[i]<0)perm.push_back(abs(s[i]));
}
sort(perm.begin(), perm.end());
do{
int cnt=0;
vector<int> helyes(2*n), copi=s;
for(int i=0;i<n;i++){
helyes[2*i]=-1*perm[i];
helyes[2*i+1]=perm[i];
}
for(int i=0;i<2*n;i++){
for(int j=i;j<2*n;j++){
if(copi[j]==helyes[i]){
while(j!=i){
swap(copi[j], copi[j-1]);
j--;
cnt++;
}
break;
}
}
ans=min(ans, cnt);
}
while(next_permutation(perm.begin(), perm.end()));
return ans;
}