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 namespace std;
long long minimum_walk(vector<int> p, int s) {
int n = p.size();
vector mover(n,0);
int last_voilater = 0;
long long ans = 0;
for(int i=0;i<n;i++) {
if(p[i]==i)continue;
ans+=abs(p[i]-i);
last_voilater=i;
mover[min(p[i],i)]++;
mover[max(p[i],i)]--;
}
for(int i=1;i<n;i++)mover[i]+=mover[i-1];
for(int i=0;i<last_voilater;i++) {
if(mover[i]==0)ans+=2;
}
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... |