# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
815426 | elotelo966 | Arranging Shoes (IOI19_shoes) | C++17 | 0 ms | 296 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long count_swaps(std::vector<int> s) {
int n=s.size()*2;
vector <int> v(n);
vector <pair<int,int>> ger;
vector <int> cev,cev1;
for(int i=0;i<n;i++)v[i]=s[i];
int dizi[n],ind[n];
int tut=0;
for(int i=0;i<n;i++){
if(v[i]<0){
dizi[tut]=v[i];
ind[tut]=i;
tut+=2;
}
else{
ger.push_back({v[i],i});
}
}
sort(ger.begin(),ger.end());
for(int i=0;i<ger.size();i++){
cev.push_back(ger[i].first);
cev1.push_back(ger[i].second);
//cout<<ger[i].first<<" "<<ger[i].second<<endl;
}
for(int i=0;i<n;i+=2){
int c=lower_bound(cev.begin(),cev.end(),-dizi[i])-cev.begin();
ind[i+1]=cev1[c];
cev.erase(cev.begin()+c);
cev1.erase(cev1.begin()+c);
}
int ans=0;
for(int i=0;i<n;i++){
// cout<<ind[i]<<" "<<abs(ind[i]-i)<<endl;
ans+=abs(ind[i]-i);
}
if((ans/2)%2==0)return ans/2;
return ans/2+1;
}
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... |