# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
146776 | youssan_william | 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.
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
typedef long long ll;
bool v[100005];
ll count_swaps( vector<ll>s )
{
ll n = s.size()/2 ;
ll ans=0;
for(int i = 1 ; i <=2*n ; i++)
{
if(!v[abs(s[i])])
{
v[abs(s[i])]=1;
for(int j =i+1 ; j <= 2 * n ;j++)
{
if(abs(s[i])==abs(s[j]))
{
for(int k=j-1 ; k>i ;k--)
{
swap(s[k],s[k+1]);
ans++;
}
break;
}
}
}
}
for(int i = 1 ; i <=2*n ;i++ )
{
if(i%2==1&&s[i]>s[i+1])
ans++;
}
return ans;
}