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 <cstdio>
#include <vector>
#include <cassert>
#include <cstdlib>
using namespace std;
long long minimum_walk(std::vector<int> p, int s) {
int n = p.size(), last = 0;
long long total = 0;
for(int i=0; i<n; i++) {
if (i==p[i]) continue;
if(i>last) total += (i-last)*2;
total += abs(p[i]-i);
last = max(last,i);
int idx = p[i]; p[i] = i;
while(idx!=i) {
last = max(last,idx);
total += abs(p[idx]-idx);
int prevIdx = idx;
idx = p[idx];
p[prevIdx] = prevIdx;
}
}
return total;
}
# | 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... |