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 <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
long long count_swaps(std::vector<int> s) {
int n = s.size()/2;
vector<pair<int, bool>>shoes(2*n);
for(int i =0 ; i<2*n; ++i)
{
shoes[i] = {abs(s[i]), s[i] < 0};
}
long long numSwaps = 0;
//sort(shoes.begin(), shoes.end());
int currShoe = 0;
while(currShoe < 2*n)
{
int findShoe = shoes[currShoe].first;
int findShoeSign = !(shoes[currShoe].second);
pair<int, bool> lastEl = {findShoe, findShoeSign};
for(int i = 1; i<(2*n-currShoe); ++i)
{
swap(lastEl, shoes[currShoe+ i]);
if(lastEl.first == findShoe && lastEl.second == findShoeSign)
{
//found
break;
}
numSwaps++;
}
if(shoes[currShoe].second == 0)
{
numSwaps++;
swap(shoes[currShoe], shoes[currShoe+1]);
}
currShoe+=2;
}
return numSwaps;
}
# | 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... |