This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Ignut
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 123;
ll count_swaps(vector<int> S) {
ll res = INF;
int n = S.size();
vector<int> vec = S;
sort(vec.begin(), vec.end());
for (int i = 1; i <= n / 2; i ++) vec.pop_back();
do {
vector<int> s = S;
vector<int> t;
for (int val : vec) {
t.push_back(val);
t.push_back(-val);
}
int ans = 0;
for (int i = 0; i < n; i ++) {
int j;
for (j = i; j < n; j ++)
if (s[j] == t[i])
break;
while (j > i) {
swap(s[j - 1], s[j]);
j --;
ans ++;
}
}
// for (int val : t) cout << val << ' ';
// cout << " : " << ans << '\n';
res = min(res, 1ll * ans);
} while (next_permutation(vec.begin(), vec.end()));
return res;
}
# | 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... |