# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
543074 | Anas_AbuAmar | 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 <bits/stdc++.h>
using namespace std;
long long count_swaps(std::vector<int> s) {
long long ans = 0;
deque<int>d;
for (auto &i:s){
d.push_back(i);
}
while(!d.empty()){
int cur = d.front();
auto next = find(d.begin() , d.end() ,cur*-1);
ans += (next-d.begin())-1;
if (cur > 0 ){
ans++;
}
d.erase(next);
d.pop_front();
}
return ans;
}
int main() {
int n;
assert(1 == scanf("%d", &n));
vector<int> S(2 * n);
for (int i = 0; i < 2 * n; i++)
assert(1 == scanf("%d", &S[i]));
fclose(stdin);
long long result = count_swaps(S);
printf("%lld\n", result);
fclose(stdout);
return 0;
}