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;
#define ll long long
ll minimum_walk(vector<int> p, int s) {
int n=p.size();
ll ans=0;
vector<int> a(n);
for(int i=0; i<n; ++i) {
ans+=abs(i-p[i]);
++a[min(i, p[i])];
--a[max(i, p[i])];
}
for(int i=0; i+1<n; ++i) {
a[i+1]+=a[i];
ans+=2*!a[i];
}
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... |