이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |