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>
#define inf 1000000000000000000ll
#define ab(x) ((x)>0?(x):-(x))
#define L long long
using namespace std;
L n;
L chk[1000010];
L minimum_walk(vector<int>p,int s){
L i,ret=0,las=0;
n=p.size();
for(i=0;i<n;i++)
{
if(!chk[i]&&p[i]!=i)
{
las=i;
L temp=p[i];
ret+=ab(p[i]-i);
chk[temp]=1;
while(temp!=i)
{
ret+=ab(p[temp]-temp);
temp=p[temp];
chk[temp]=1;
}
}
}
return ret+las*2;
}
# | 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... |