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 int long long
#define vec vector
long long minimum_walk(std::vector<int32_t> P, int32_t S) {
int ans = 0;
int N = P.size();
for(int i = 0; i<N; i++) {
ans += abs(P[i]-i);
}
int r = P[0];
for(int i = 1; i<N; i++) {
if(r < i) ans += 2;
r = max((int) P[i], r);
}
for(int i = 0; i<S; i++) {
if(P[i] != i) break;
ans -= 2;
}
for(int i = N-1; i>S; i--) {
if(P[i] != i) break;
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... |