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 ll = long long;
using namespace std;
int n;
bool vis[1000007];
long long minimum_walk(std::vector<int> p, int s) {
ll res = 0;
n = p.size();
int maxd = 0;
for(int i = 0 ; i < n ; i++) {
if(vis[i])
continue;
int w = i;
int mind = 1e9;
while(!vis[w]) {
vis[w] = 1;
mind = min(mind, abs(s - w));
res += abs(p[w] - w);
w = p[w];
}
maxd = max(maxd, mind);
}
res += maxd * 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... |