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 "public_c/public/cpp/books.h"
#include "books.h"
#include <bits/stdc++.h>
long long minimum_walk(std::vector <int> p, int s) {
int n = p.size();
std::vector <bool> vis(n, false);
int big = 0;
long long ans = 0;
for (int i = 0; i < n; i++) {
if (vis[i] || i == p[i]) {
continue;
}
vis[i] = true;
big = i;
int u = i;
do {
ans += abs(p[u] - u);
u = p[u];
vis[u] = true;
} while (u != i);
}
ans += big * 2;
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... |