이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |