이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
//n = 1 its either 1 or 0
//n = 8 we can brutazo
//all shoes are same, we just need to get all inversion (even is left, odd is right)
//all shoes need to travel n?
//eta ~ 25 minutes
/*full solutions*/
//O(N^2)
/*
dp[n][i]
//min swaps at position i after considering n pairs?
*/
/*SUBTASK 1, 3, 4*/
/*
long long count_swaps(vector<int> s) {
ll ans = 0;
int n = s.size();
int first = 0;
for(int i =0; i<n; i++){
if(s[i] < 0){
ans += abs(i - first);
first +=2;
}
}
return ans;
}
*/
/*SUBTASK 2*/
long long count_swaps(vector<int> s) {
ll ans = 1e18;
int n = s.size();
vector<int> lefts(n/2);
int cntleft = 0;
for(int i =0; i<n; i++){
if(s[i] < 0){
lefts[cntleft++] = i;
}
}
do{
ll posans = 0;
vector<bool> available(n, 1);
//for(int i =0; i<n/ 2; i++) cout << lefts[i]<<", "; cout <<endl;
for(int l =0; l<n/2; l++){
//get first availabe
int firstright =-1;
for(int i =0; i<n ;i++){
if(available[i] and s[i] == -s[lefts[l]]){
firstright = i;
available[i] = false;
break;
}
}
//cout << lefts[l]<<", "<<firstright<<endl;
posans += abs(lefts[l] - 2 * l) + abs(firstright -( 2 * l + 1));
}
ans = min(ans, posans/2);
}while(next_permutation(lefts.begin(), lefts.end()));
return ans;
}
/***********/
# | 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... |