이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |