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 minimum_walk(std::vector<int> p, int s) {
int n = p.size();
vector<bool> vis(n);
long long ans = 0;
int right = 0;
for (int i = 0; i < n; i++) if (i != p[i] && !vis[i]) {
right = max(right, i);
int tmp = i;
while (!vis[tmp]) {
ans += abs(tmp - p[tmp]), vis[tmp] = 1, tmp = p[tmp];
}
}
return ans + 2 * right;
}
# | 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... |