#include <bits/stdc++.h>
using namespace std;
long long count_swaps(vector<int> Shoes)
{
long long n = Shoes.size() / 2;
bool LeftRightShoes = true;
for (int i = 0; i < n; i++)
{
if (Shoes[i] > 0)
{
LeftRightShoes = false;
break;
}
}
if (LeftRightShoes)
{
for (int i = n; i < 2 * n; i++)
{
if (Shoes[i] < 0)
{
LeftRightShoes = false;
break;
}
}
}
if (LeftRightShoes)
{
return (n * (n - 1)) / 2;
}
long long Answer = 0;
while (Shoes.size() != 0)
{
int FirstShoe = Shoes[0];
int Matching = -FirstShoe;
int Dist = 0;
auto it = Shoes.begin() + 1;
while (*it != Matching)
{
++it;
Dist++;
}
Shoes.erase(it);
Shoes.erase(Shoes.begin());
Answer += Dist;
if (FirstShoe < 0)
{
Answer++;
}
}
return Answer;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |