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>
using namespace std;
long long n,to[3000],pairs=0,br=0;
queue <long long> found[3000];
long long from[3000],perm[3000];
long long count_swaps(vector <int> shoes)
{
long long i,j;
n=shoes.size()/2;
for(i=0;i<2*n;i++)perm[i]=i;
for(i=0;i<2*n;i++)
{
if(shoes[i]<0)
{
if(found[shoes[i]+n].empty()==false)
{
to[i]=found[shoes[i]+n].front();
found[shoes[i]+n].pop();
}
else
{
to[i]=pairs;
found[n-shoes[i]].push(pairs+1);
pairs+=2;
}
}
else
{
if(found[shoes[i]+n].empty()==false)
{
to[i]=found[shoes[i]+n].front();
found[shoes[i]+n].pop();
}
else
{
to[i]=pairs+1;
found[n-shoes[i]].push(pairs);
pairs+=2;
}
}
}
for(i=0;i<2*n;i++)from[to[i]]=i;
//for(i=0;i<2*n;i++)cout<<to[i]<<' ';cout<<endl;
//for(i=0;i<2*n;i++)cout<<from[i]<<' ';cout<<endl;
for(i=0;i<2*n;i++)
{
for(j=0;j<perm[from[i]];j++)
{
perm[j]++;
}
br+=abs(i-perm[from[i]]);
}
return br/2+br%2;
}
| # | 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... |