이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
const int THRESHOLD = 13;
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);
} else 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);
swap(curr[0],currhand);
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... |