# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
784132 | Alfraganus | 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 "shoes.h"
#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
long long count_swaps(vector<int> a) {
long long n = a.size() / 2;
if(n == 1)return a[0] > 0;
vector<vector<int>> pos(2 * n + 1);
for(int i = 2 * n - 1; i >= 0; i --)
pos[a[i] + n].push_back(i);
long long ans = 0;
for(int i = 0; i < 2 * n; i ++){
if(a[i] != 0){
ans += pos[-a[i] + n].back() - i;
if(a[i] < 0)ans --;
a[pos[-a[i] + n].back()] = 0;
pos[-a[i] + n].pop_back();
pos[a[i] + n].pop_back();
a[i] = 0;
}
}
return ans;
}