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;
typedef long long ll;
const int Nmax = 1e6 + 5;
bool used[Nmax];
int mdl(int x) { return (x > 0 ? x : -x); }
ll minimum_walk(vector<int> p, int s)
{
int n = p.size();
int i, last = 0;
ll ans = 0;
for(i=0; i<n; ++i)
if(!used[i])
{
int x = i;
do
{
ans += mdl(x - p[x]);
used[x] = 1;
x = p[x];
}
while(x != i);
if(i != p[i]) last = i;
}
ans += 2 * last;
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... |