# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1030239 | ender | Arranging Shoes (IOI19_shoes) | C++17 | 1 ms | 348 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
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(s[i] == curr[i]) continue;
for(int j = i+1; j < s.size(); ++j){
if(s[j] == curr[i]){
for(int k = j; k > i; --k){
swap(s[k], s[k-1]);
cnt++;
}
break;
}
}
}else { // debe ser zapato derecho
if(s[i] == s[i-1] * -1) continue;
int target = s[i-1] * -1;
cout << s[i] << " " << target << " " << curr[i] << "\n";
for(int j = i+1; j < s.size(); ++j){
if(s[j] == target){
for(int k = j; k > i; --k){
swap(s[k], s[k-1]);
cnt++;
}
break;
}
}
}
}
ans = min(cnt, ans);
for(const auto &i : s ) cout << i << " ";
cout << "\n";
cout << ans << "\n";
} 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... |