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;
#include <vector>
long long minimum_walk(std::vector<int> p, int s) {
int n = p.size(), total = 0, prevIdx = 0;
std::vector<int> v(n,0);
for(int i=0; i<n; i++) {
if (i==p[i]) continue;
int idx = i;
total += idx - prevIdx;
// printf("prevIdx=%d, idx=%d, idx-prevIdx=%d, total=%d\n",prevIdx,idx,idx-prevIdx,total);
while(idx!=p[idx]) {
total += abs(p[idx]-idx);
// printf("prevIdx=%d, idx=%d, p[%d]=%d, abs(p[%d]-idx)=%d, total=%d\n",prevIdx,idx,idx,p[idx],idx,abs(p[idx]-idx),total);
prevIdx = idx; idx = p[idx];
p[prevIdx] = prevIdx;
}
prevIdx = idx;
// printf("prevIdx=%d, idx=%d, p[%d]=%d\n",prevIdx,idx,idx,p[idx],idx);
}
return total + prevIdx;
}
# | 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... |