# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143864 | Bodo171 | Arranging Shoes (IOI19_shoes) | C++14 | 1087 ms | 19192 KiB |
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 <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int nmax=200005;
vector<int> v[2][nmax];
struct pr
{
int x,y;
}a[nmax];
bool comp(pr unu,pr doi)
{
return ((unu.x+unu.y)<(doi.x+doi.y));
}
int fin[nmax],po[nmax];
int nr,i,j,mn,col,poz;
int abss(int x)
{
if(x<0) return -x;
return x;
}
long long count_swaps(vector<int> s) {
int n=s.size();
n/=2;int ans=0;
for(int i=0;i<2*n;i++)
{
v[(s[i]>0)][abss(s[i])].push_back(i);
}
ans=0;
for(i=1;i<=n;i++)
{
for(j=0;j<v[0][i].size();j++)
{
a[nr++]={v[0][i][j],v[1][i][j]};
}
}
sort(a,a+nr,comp);
for(i=0;i<nr;i++)
{
fin[a[i].x]=2*i;
fin[a[i].y]=2*i+1;
}
for(i=0;i<2*n;i++)
for(j=i+1;j<2*n;j++)
ans+=(fin[i]>fin[j]);
return ans;
}
Compilation message (stderr)
# | 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... |