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 <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int inf=100;
int n;
const int cap=10;
int rek(int x, int d, int t, vector < int > l){
if(d>cap || x>=n || x<0){
return inf;
}
if(!x){
bool p=1;
if(l[0]!=0 && t){
p=0;
}
for(int i=1; i<n; i++){
if(l[i]!=i){
p=0;
break;
}
}
if(p){
return d;
}
}
int mini=inf;
mini=min(mini, rek(x+1, d+1, t, l));
mini=min(mini, rek(x-1, d+1, t, l));
swap(l[x], t);
mini=min(mini, rek(x+1, d+1, t, l));
mini=min(mini, rek(x-1, d+1, t, l));
return mini;
}
ll minimum_walk(vector < int > p, int s) {
n=p.size();
return rek(0, 0, -1, p);
}
# | 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... |