# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1215273 | ColourAttila | Arranging Shoes (IOI19_shoes) | C++17 | 0 ms | 0 KiB |
long long count_swaps_subt2(vector<int>v){
ll n = (ll)v.size();
vector<int> e;
for(auto i : v) if(i < 0) e.push_back(i);
sort(e.begin(), e.end());
ll cv = 1e9;
do{
vector<int>p;
for(ll i = 0; i < e.size(); i ++) p.push_back(e[i]), p.push_back(-e[i]);
ll say = 0;
vector<int> a = v;
for(ll i = 0; i < n; i ++){
if(a[i] == p[i]) continue;
ll j;
for(j = i + 1; j < n; j ++){
if(a[j] == p[i]) break;
}
for(; j > i; j --){
say ++;
a[j] = a[j - 1];
}
a[i] = p[i];
}
cv = min(cv, say);
}while(next_permutation(e.begin(), e.end()));
return cv;
}