이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
long long n,to[2500],pairs=0,br=0;
queue <long long> found[2500];
long long from[2500],perm[2500];
long long count_swaps(vector <int> shoes)
{
long long i,j;
n=shoes.size();
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]]);
}
cout<<br/2<<endl;
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... |