# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1224866 | im2xtreme | Arranging Shoes (IOI19_shoes) | C++20 | 0 ms | 0 KiB |
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
int64 count_swaps(vector<int> S) {
int n = S.size();
vector<bool> used(n, false);
int64 swaps = 0;
for (int i = 0; i < n; i++) {
if (used[i]) continue;
if (S[i] < 0) {
for (int j = i + 1; j < n; j++) {
if (!used[j] && S[j] == -S[i]) {
for (int k = j; k > i + 1; k--) {
swap(S[k], S[k - 1]);
swaps++;
}
used[i] = true;
used[i + 1] = true;
break;
}
}
}
}
return swaps;
}