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 "books.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e6+5;
int vs[nx], n, lst;
ll res;
long long minimum_walk(std::vector<int> p, int s) {
n=p.size();
for (int i=0; i<n; i++) vs[i]=0;
res=0;
for (int i=0; i<n; i++)
{
if (vs[i]) continue;
lst=i;
vs[i]=1;
int cur=i;
while (p[cur]!=i) res+=abs(p[cur]-cur), cur=p[cur], vs[cur]=1;
res+=abs(p[cur]-cur);
}
return res+2*lst;
}
# | 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... |