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"
using namespace std;
long long count_swaps(vector <int> shoes) {
long long n = shoes.size();
unordered_map<long long, long long> size_count;
for (long long i = 0; i < n; i++) {
size_count[shoes[i]] = size_count[shoes[i]] + 1;
}
long long swaps = 0;
for (long long i = 0; i < n; i++) {
if (shoes[i] < 0) {
continue;
}
long long matching_shoe = -shoes[i];
if (size_count[matching_shoe] <= 0) {
continue;
}
size_count[matching_shoe]--;
long long j = i + 1;
while (shoes[j] != matching_shoe) {
j++;
}
swap(shoes[i], shoes[j]);
swaps += j - i;
}
return swaps;
}
# | 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... |