# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1030256 | ender | Arranging Shoes (IOI19_shoes) | C++17 | 1091 ms | 5432 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 count_swaps(std::vector<int> s) {
int n = s.size()/2;
vector<int> p;
for(int i = 1; i <= n; ++i) p.push_back(i);
long long ans = 1e18;
do{
long long cnt = 0;
vector<int> curr; // same size as s
vector<int> current_s(s.begin(), s.end());
for(int i = 0; i < n; ++i){
curr.push_back(-p[i]);
curr.push_back(p[i]);
}
for(int i = 0; i < s.size(); ++i){
if(i%2 == 0){ // debe ser zapato izquierdo
if(current_s[i] == curr[i]) continue;
for(int j = i+1; j < s.size(); ++j){
if(current_s[j] == curr[i]){
for(int k = j; k > i; --k){
swap(current_s[k], current_s[k-1]);
cnt++;
}
break;
}
}
}else { // debe ser zapato derecho
if(current_s[i] == current_s[i-1] * -1) continue;
int target = current_s[i-1] * -1;
for(int j = i+1; j < s.size(); ++j){
if(current_s[j] == target){
for(int k = j; k > i; --k){
swap(current_s[k], current_s[k-1]);
cnt++;
}
break;
}
}
}
}
ans = min(cnt, ans);
} while (next_permutation(p.begin(), p.end()));
return ans;
}
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... |