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(vector<int> s){
auto a = s;
int N = a.size(), n = N / 2;
vector<int> b;
for (int i = 0; i < N; i++)
if (a[i] < 0)
b.push_back(a[i]);
sort(b.begin(), b.end());
long long ans = 1ll * N * N;
do {
long long cnt = 0;
vector<int> c(N);
for (int i = 0; i < n; i++)
c[2 * i] = b[i], c[2 * i + 1] = -b[i];
vector<int> aa = a;
for (int i = 0; i < N; i++){
int j = i;
while (j < N && aa[j] != c[i]) j++;
while (j > i){
swap(aa[j], aa[j - 1]);
j--;
cnt++;
}
}
ans = min(ans, cnt);
}while (next_permutation(b.begin(), b.end()));
return ans;
}
# | 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... |