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 <bits/stdc++.h>
#include "shoes.h"
#define ll long long
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
long long count_swaps(std::vector<int> s) {
int n = sz(s);
if (n / 2 <= 8) {
vector<int> who;
for (int i = 0; i < n; i++) {
if (s[i] < 0) who.emplace_back(s[i]);
}
sort(all(who));
ll ans = 1e18;
do {
vector<bool> vis(n);
vector<int> where(n);
for (int i = 0; i < n; i++) {
int fd = who[i / 2] * (i % 2 == 0 ? 1 : -1);
for (int j = 0; j < n; j++) {
if (s[j] == fd && !vis[j]) {
vis[j] = 1, where[i] = j; break;
}
}
}
ll inv = 0;
for (int i = 0; i < n; i++) for (int j = i+1; j < n; j++) inv += where[i] > where[j];
ckmin(ans, inv);
}
while (next_permutation(all(who)));
return ans;
}
return 0;
}
# | 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... |