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 lst = 0;
for (int i = 0; i < n; i++) if (!vis[i]) {
ans += 2 * (i - lst);
int tmp = i;
long long cur = 0;
while (!vis[tmp]) {
cur += abs(tmp - p[tmp]), vis[tmp] = 1, tmp = p[tmp];
}
lst = tmp;
ans += cur;
}
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... |