#include <bits/stdc++.h>
using namespace std;
int count_swaps(vector<int>shoes)
{
int n = shoes.size() / 2;
bool samesize = true;
bool leftrightshoes = true;
for (int i = 0; i < n * 2; i++)
{
int a = shoes[i];
if (i != 0)
{
if (a + shoes[i - 1] == 0 || a + shoes[i - 1] == a * 2) samesize = false;
}
if ((i <= n - 1 && a > 0) || (i > n - 1 && i <= n * 2 - 1 && a < 0)) leftrightshoes = false;
shoes[i] = a;
}
if (n == 1)
{
if (shoes[0] > shoes[1])
{
return 1;
}
else
{
return 0;
}
}
else if (samesize)
{
int answer = 0;
for (int i = 0; i < n * 2; i += 2)
{
if (i % 2 == 0 && shoes[i] > 0)
{
answer++;
}
}
return answer;
}
int answer = (n * (n - 1)) / 2;
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... |