#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define isz(x) (int)x.size()
long long count_swaps(std::vector<int> s) {
vector<int> a = s;
int n = isz(a);
return (((n >> 1) * ((n >> 1) - 1)) >> 1);
if (n == 2) {
return (a[0] > 0);
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (i % 2 == 0 && a[i] > 0) {
int d = 1e9;
for (int j = i + 1; j < n; j++) {
if (a[j] + a[i] == 0) {
d = j;
break;
}
}
ans += (d - i);
for (int j = d; j > i; j--) swap(a[j], a[j - 1]);
continue;
}
if (i % 2 == 1 && (a[i] < 0 || (a[i - 1] + a[i]) != 0)) {
int d = 1e9;
for (int j = i + 1; j < n; j++) {
if (a[j] + a[i - 1] == 0) {
d = j;
break;
}
}
ans += (d - i);
for (int j = d; j > i; j--) swap(a[j], a[j - 1]);
}
}
for (int i = 0; i < n; i += 2) {
ans += (a[i] > 0);
}
return ans;
}
| # | 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... |