# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
919993 | tanprodium | Arranging Shoes (IOI19_shoes) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "shoes.h"
ll count_swaps(vector<int> a) {
int n = (int)a.size() / 2;
ll ans = 0;
for (int i = 0; i < 2 * n; i += 2) {
if (a[i] < 0) {
for (int j = i + 1; j < 2 * n; j++)
if (a[j] == -a[i]) {
ans += j - i - 1;
for (int k = j - 1; k >= i + 1; k--)
swap(a[k], a[k + 1]);
break;
}
} else {
for (int j = i + 1; j < 2 * n; j++)
if (a[j] == -a[i]) {
ans += j - i;
for (int k = j - 1; k >= i; k--)
swap(a[k], a[k + 1]);
break;
}
}
}
return (ans);
}