# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
681145 | Ronin13 | 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 <iostream>
#include <unordered_map>
#include "shoes.h"
#define int long long
using namespace std;
int count_swaps(vector <int> shoes) {
int n = shoes.size();
unordered_map<int, int> size_count;
for (int i = 0; i < n; i++) {
size_count[shoes[i]] = size_count[shoes[i]] + 1;
}
int swaps = 0;
for (int i = 0; i < n; i++) {
if (shoes[i] < 0) {
continue;
}
int matching_shoe = -shoes[i];
if (size_count[matching_shoe] <= 0) {
continue;
}
size_count[matching_shoe]--;
int j = i + 1;
while (shoes[j] != matching_shoe) {
j++;
}
swap(shoes[i], shoes[j]);
swaps += j - i;
}
return swaps;
}