#include <bits/stdc++.h>
using namespace std;
long long count_swaps(vector<int>Shoes) {
vector<int>ShoesQueue = Shoes;
int Answer = 0;
int TargetShoeSize = 0;
bool AllSameSize = true;
for (int i = 0; i < ShoesQueue.size(); i++)
{
int Size = ShoesQueue[i];
int AbsoluteSize = abs(Size);
if (i == 0)
{
TargetShoeSize = AbsoluteSize;
}
else if (TargetShoeSize != AbsoluteSize)
{
AllSameSize = false;
}
}
if (AllSameSize)
{
int Index = 0;
int LeftShoes = 0;
while (!ShoesQueue.empty())
{
int FirstShoe = ShoesQueue[Index];
if (FirstShoe < 0)
{
int TargetPosition = LeftShoes * 2;
int Distance = abs(TargetPosition - Index);
Answer += Distance;
LeftShoes++;
}
Index++;
}
return Answer;
}
while (!ShoesQueue.empty())
{
int FirstShoe = -(*ShoesQueue.begin());
int DistanceToPair = 0;
auto it = ++ShoesQueue.begin();
while (*it != FirstShoe)
{
++it;
DistanceToPair++;
}
ShoesQueue.erase(it);
ShoesQueue.erase(ShoesQueue.begin());
Answer += DistanceToPair;
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... |