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>
using namespace std;
using ll = long long; using pii = pair<ll,ll>;
ll minimum_walk(vector<int> p, int s) {
ll N = p.size();
assert(s==0);
ll ans = 0;
bool found[N];
for (ll i=0;i<N;i++) {
found[i]=0;
}
ll D = 0;
for (ll i=0;i<N;i++) {
if (!found[i]) {
ll j = i;
ll dmin = 1e8;
do {
found[j]=1;
dmin = min(dmin,j);
ans += abs(p[j]-j);
j = p[j];
} while (j != i);
D = max(D,dmin);
}
}
ans += 2*D;
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... |