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;
long long minimum_walk(vector<int> pos, int gau)
{
int n = pos.size(), Max = 0;
long long ans = 0;
for(int i = 0; i < n; i++)
{
if(pos[i] == i) continue;
ans += i - Max;
Max = max(Max, i);
int p = pos[i], old = i;
while(true)
{
ans += abs(p - old);
if(p == i) break;
int gau = pos[p];
old = p;
pos[p] = p;
p = gau;
}
}
return ans + Max;
}
# | 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... |