# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
784241 | HD1 | Arranging Shoes (IOI19_shoes) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//we are all lost trying to be someone.
#include "shoes.h"
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define sz(x) ll(x.size())
#define reve(x) reverse(x.begin(),x.end())
#define ff first
#define ss second
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ll, ii >tri;
const ll MAX=1e7+100;
const ll mod=1e9+7;
const ll inf=1e9;
vector<ll> z,s;
map<ll,ll>Mp;
ll cost(ll x, ll aux){
ll ans=0;
for(ll i=0; i<sz(z); i++){
if(z[i]!=x)continue;
ll pos=i;
while(pos!=aux){
pos--;
swap(z[i],z[i-1]);
ans++;
}
break;
}
return ans;
}
ll brute(){
ll ans=0;
ll pos=0;
for(ll i=0; i<sz(s); i++){
ans+=cost(s[i]*-1,pos);
pos++;
ans+=cost(s[i],pos);
pos++;
}
}
long long count_swaps(vector<ll> c){
ll mn=1e18;
for(ll i=2; i<=sz(c); i+=2){
s.push_back(i/2);
}
do{
z=c;
mn=min(mn,brute());
}while(next_permutation(s.begin(),s.end()));
return mn;
}