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 "books.h"
#include <bits/stdc++.h>
using namespace std;
const int THRESHOLD = 10;
long long minimum_walk(vector<int> p, int s) {
int n = p.size();
vector<int> res(n,-1);
for(int i=0;i<n;i++)res[p[i]]=i;
long long ans = 1e10;
vector<int> curr(n);iota(curr.begin(), curr.end(),0);
int currhand = 0;
curr[0]=-1;
function<void(int,long long,int)> calc = [&](int x,long long t,int moves) {
if(moves>THRESHOLD)return;
swap(currhand,curr[x]);
if(curr==res) {
ans = min(ans,t+x);
return;
}
for(int i=0;i<n;i++)if(i!=x) {
calc(i,t+abs(x-i),moves+1);
}
swap(currhand,curr[x]);
};
calc(0,0,0);
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... |