#include <bits/stdc++.h>
using namespace std;
long long count_swaps(vector<int>Shoes) {
vector<int>ShoesQueue = Shoes;
int Answer = 0;
int TargetShoeSize = Shoes[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 SameSizeAnswer = 0;
int c1 = 0;
int c2 = 0;
int cnt = 0;
for (int i = 0; i < ShoesQueue.size(); i++)
{
int Shoe = ShoesQueue[i];
if (Shoe < 0 && i % 2 == 1)
{
cnt += (i - c1 * 2);
c1++;
}
else if (Shoe > 0 && i % 2 == 0)
{
cnt += (i - c2 * 2 - 1);
c2++;
}
}
SameSizeAnswer = cnt / 2;
return SameSizeAnswer;
}
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... |