# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
387482 | kimbj0709 | Arranging Shoes (IOI19_shoes) | C++14 | 151 ms | 19048 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;
long long int ans = 0;
vector<int> merge_sort(vector<int> vect1){
if(vect1.size()<=1){
return vect1;
}
vector<int> left,right;
for(int i=0;i<vect1.size()/2;i++){
left.push_back(vect1[i]);
}
for(int i=vect1.size()/2;i<vect1.size();i++){
right.push_back(vect1[i]);
}
left = merge_sort(left);
right = merge_sort(right);
vector<int> curr;
left.push_back(INT_MAX);
right.push_back(INT_MAX);
reverse(left.begin(),left.end());
reverse(right.begin(),right.end());
for(int i=0;i<vect1.size();i++){
if(left.back()<right.back()){
curr.push_back(left.back());
left.pop_back();
}
else{
ans += left.size()-1;
curr.push_back(right.back());
right.pop_back();
}
}
return curr;
}
long long count_swaps(std::vector<int> s) {
int n = s.size();
vector<vector<int> > nexts(s.size()*2+100);
for(int i=0;i<s.size();i++){
if(s[i]>0){
nexts[s[i]].push_back(i);
}
else{
nexts[-2*s[i]].push_back(i);
}
}
for(int i=0;i<nexts.size();i++){
reverse(nexts[i].begin(),nexts[i].end());
}
vector<int> treated(s.size(),0);
int currpos = 0;
vector<int> positions(n,-1);
for(int i=0;i<n;i++){
if(treated[i]==1){
continue;
}
if(s[i]<0){
positions[i] = currpos;
positions[nexts[s[i]*-1].back()] = currpos+1;
treated[nexts[s[i]*-1].back()] = 1;
nexts[s[i]*-2].pop_back();
nexts[s[i]*-1].pop_back();
}
else{
positions[i] = currpos+1;
positions[nexts[s[i]*2].back()] = currpos;
treated[nexts[s[i]*2].back()] = 1;
nexts[s[i]*2].pop_back();
nexts[s[i]].pop_back();
}
currpos += 2;
}
merge_sort(positions);
return ans;
}
/*int main(){
int n;
cin >> n;
vector<int> vect1;
int input;
for(int i=0;i<2*n;i++){
cin >> input;
vect1.push_back(input);
}
cout << count_swaps(vect1);
}
*/
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... |