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>
#define mod 1000000007LL
#define inf 1e17
#define ll long long
using namespace std;
void printvec(vector<int> vec)
{
for (auto &&e : vec)
{
cout << e << ' ';
}
cout << endl;
}
ll count_swaps(vector<int> s)
{
ll n = s.size()/2;
ll ans = inf;
vector<pair<ll,ll>> perm;
for (int i = 0; i < 2*n; i++)
{
if(s[i] > 0)
{
perm.push_back({-s[i], s[i]});
}
}
sort(perm.begin(), perm.end());
vector<int> temp = s;
do
{
s = temp;
ll subans = 0;
vector<int> v;
for (int i = 0; i < n; i++)
{
v.push_back(perm[i].first);
v.push_back(perm[i].second);
}
for (int i = 0; i < 2*n; i++)
{
if(s[i]!=v[i])
{
for (int j = i+1; j < 2*n; j++)
{
if(v[j] == s[j-1] && s[j]!=s[j-1]){swap(s[j], s[j-1]);subans++;i--;break;}
swap(s[j], s[j-1]);
if(s[j]!=s[j-1]) subans++;
}
}
}
ans = min(ans, subans);
} while (next_permutation(perm.begin(), perm.end()));
return ans;
}
// int main()
// {
// cout << count_swaps({-1,1,-1,-1,-1,1,1,1}) << endl;
// }
# | 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... |