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>
using namespace std;
#define ll long long
#define vll vector<ll>
#define all(x) begin(x),end(x)
#define pb push_back
ll ans=1e9;
void recur(ll i,ll n,vector<ll> p,ll hand,ll dist=0)
{
bool check=1;
for(int j=0;j<n;j++)
check&=(p[j]==j);
if(check and dist<ans and i==0)
ans=dist;
if(dist>13 or dist>=ans)return;
if(i<0 or n<=i)return;
recur(i+1,n,p,hand,dist+1);
recur(i-1,n,p,hand,dist+1);
swap(p[i],hand);
check=1;
for(int j=0;j<n;j++)
check&=(p[j]==j);
if(check and dist<ans and i==0)
ans=dist;
recur(i+1,n,p,hand,dist+1);
recur(i-1,n,p,hand,dist+1);
}
long long minimum_walk(std::vector<int> p, int s)
{
int n=p.size();
// Solve for s==0
ans=1e9;
vll tp;
for(auto j:p)tp.pb(j);
recur(s,n,tp,-1);
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... |