# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
465875 | dattranxxx | 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.
/*
* Author : shora
*/
#include "shoes.h"
#include <bits/stdc++.h>
#define print(_v) for (auto &_ : _v) {cerr << _ << ' ';} cerr << endl;
using namespace std;
using ll = long long;
const int oo = 1e9;
ll n;
namespace task_5 {
ll solve(vector<int>& a) {
ll res = 0;
for (int i = 0; i < a.size(); i += 2) {
int j = find(a.begin() + i + 1, a.end(), -a[i]) - a.begin();
int lim = a[i] < 0 ? j-i-1 : j-i;
for (int k = 0; k <= lim; ++k) {
swap(a[j], a[j-1]); j--;
}
res ++ lim;
}
return res;
}
}
long long count_swaps(std::vector<int> a) {
n = a.size() / 2;
return task_5::solve(a);
}