# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1215785 | bali | Arranging Shoes (IOI19_shoes) | C++20 | 0 ms | 0 KiB |
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long count_swaps(std::vector<int> s) {
vector<int> h;
for(ll i=0; i<s.size(); i++)
{
if(s[i]<0)
{
h.push_back(s[i]);
}
}
sort(h.begin(),h.end());
ll cmin=LLONG_MAX;
do
{
vector<int> h2;
for(ll i=0; i<h.size(); i++)
{
h2.push_back(h[i]);
h2.push_back(-h[i]);
}
ll c=0;
for(ll i=0; i<s.size(); i++)
{
for(ll j=h2.size()-1; j>i; j--)
{
if(s[i]==h2[j]){swap(h2[j], h2[j-1]);c++;}
}
}
cmin=min(cmin,c);
} while((next_permutation(s.begin(),s.end())));
return cmin;
}#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long count_swapsmy(std::vector<int> s) {
vector<int> h;
for(ll i=0; i<s.size(); i++)
{
if(s[i]<0)
{
h.push_back(s[i]);
}
}
sort(h.begin(),h.end());
ll cmin=LLONG_MAX;
do
{
vector<int> h2;
for(ll i=0; i<h.size(); i++)
{
h2.push_back(h[i]);
h2.push_back(-h[i]);
}
ll c=0;
for(ll i=0; i<s.size(); i++)
{
for(ll j=h2.size()-1; j>i; j--)
{
if(s[i]==h2[j]){swap(h2[j], h2[j-1]);c++;}
}
}
cmin=min(cmin,c);
} while((next_permutation(s.begin(),s.end())));
return cmin;
}