| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 681145 | Ronin13 | Arranging Shoes (IOI19_shoes) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
