#include <bits/stdc++.h>
#define ll long long
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fr first
#define se second
using namespace std;
long long minimum_walk(std::vector<int> p, int s) {
ll i, j, n=sz(p), pos, ult=s, tot=0, in=s;
for(i=n-1; i>=0; i--)
{
pos=0;
ll pr=-1,ul=-1;
for(j=0; j<n; j++)
{
if(p[j]!=j)
{
if(pr==-1)
pr=j;
ul=j;
}
}
for(j=ul-1; j>=pr; j--)
{
if(p[j]>p[j+1])
swap(p[j],p[j+1]);
}
if(pr==-1)
break;
tot=(abs(ult-pr)+abs(pr-ul)+tot);
ult=ul;
}
tot=tot+abs(ult-in);
return tot;
}
# | 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... |