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>
#include "books.h"
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,f[1000009],S,bo[1000009],G[1000009],pas,mx;
long long minimum_walk(std::vector<int> Pp, int Ss) {
a=Pp.size();S=Ss+1;
for(i=1; i<=a; i++) f[i]=Pp[i-1]+1;
zx=1;
for(i=1; i<=a; i++){
if(bo[i]==1) continue;
c=i;mx=i;
while(1){
bo[c]=1;
G[i]+=abs(c-f[c]);
mx=max(mx,c);
c=f[c];
if(c==i) break;
}
pas+=G[i];
if(G[i]!=0){
if(zx<i){
pas+=(i-zx)*2LL;
}
zx=max(zx,mx);
}
}
return pas;
}
# | 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... |