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;
ll minimum_walk(vector<int> p, int s) {
ll n = p.size();
ll base = 0;
for (int i = 0; i < n; i++) base += abs(p[i] - i);
vector<bool> vst(n);
ll numCyc = -1;
for (int i = 0; i < n; i++) {
if (vst[i]) continue;
numCyc++;
ll cur = i;
do {
cur = p[cur];
vst[cur] = true;
} while (cur != i);
}
return base + 2*numCyc;
}
# | 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... |