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 "books.h"
#include <bits/stdc++.h>
using namespace std;
long long minimum_walk(vector<int> p, int s) {
int n = p.size();
vector<bool> flag(n);
long long res = 0;
int mx = 0;
for (int i = 0; i < n; i++) {
if (!flag[i]) {
int sz = 0;
int cur = i;
while (true) {
sz++;
flag[cur] = true;
res += abs(cur - p[cur]);
cur = p[cur];
if (cur == i) {
break;
}
}
if (sz >= 2) {
mx = max(mx, i);
}
}
}
res += mx * 2;
return res;
}
# | 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... |