# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
890794 | GabrielPim | Arranging Shoes (IOI19_shoes) | C++14 | 0 ms | 0 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 <bits/stdc++.h>
#include <vector>
using namespace std;
int n,in,fi,a,co=0;
vector<pair <int,int> > v,v2,v3,v4;
vector<int> s;
void bu(void)
{
//cout<<in<<" "<<v3[in].second<<"\n";
for(int i=v3[in].second;i>in;i--)
{
swap(s[i],s[i-1]);
co++;
v3[v4[i].second].second++;
}
v3[in].second=0;
return;
}
bool c(const pair<int, int>& a, const pair<int, int>& b)
{
if (a.first < b.first) return true;
else if (a.first > b.first) return false;
else return a.second < b.second;
}
bool c2(const pair<int, int>& a, const pair<int, int>& b)
{
if (a.first > b.first) return true;
else if (a.first < b.first) return false;
else return a.second < b.second;
}
int main()
{
cin>>n;
for(int i=0;i<n*2;i++)
{
cin>>a;
s.push_back(a);
if(s[i]>0) v.push_back(make_pair(s[i],i));
else v2.push_back(make_pair(s[i],i));
}
sort(v.begin(),v.end(),c2);
sort(v2.begin(),v2.end(),c);
for(int i=0;i<v.size();i++)
{
v3.push_back(v2[i]);
v3.push_back(v[i]);
}
for(int i=0;i<v3.size();i++)
{
v4.push_back(make_pair(v3[i].second,i));
}
sort(v4.begin(),v4.end());
for(in=0;in<n*2;in++)
{
if(s[in]!=v3[in].first) break;
}
for(fi=s.size()-1;fi>=in;fi--)
{
if(s[fi]!=v3[fi].first) break;
}
for(in;in<=fi;in++)
{
bu();
}
cout<<co;
return 0;
}