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 <bits/stdc++.h>
#include "books.h"
using namespace std;
long long minimum_walk(std::vector<int> p, int s) {
#define int long long
vector< pair<int, int> > v;
for(int i = 0; i < (int)p.size(); i++){
v.push_back(make_pair(p[i], i));
}
sort(v.begin(), v.end());
int mini = numeric_limits<int>::max();
do{
int last = s;
int tot = 0;
for(int i = 0; i < (int)v.size(); i++){
tot += abs(last - v[i].second);
tot += abs(v[i].first-v[i].second);
last = v[i].first;
}
tot += abs(last - s);
mini = min(mini, tot);
}while(next_permutation(v.begin(), v.end()));
return mini;
#undef int
}
# | 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... |