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();
int d = 0, nt = 0;
for (int i=0; i<n; i++){
if (p[i] != i) nt++;
d += abs(p[i]-i);
}
int e = 0;
vector<int> q(n);
for (int i=0; i<n; i++) q[p[i]] = i;
int l = 0, r = 0, cur = 0;
while (l < n){
r = max(r, max(p[l], q[l]));
if (p[l] != l) cur++;
if (l == r && cur != nt) e++;
l++;
}
return d + 2*e;
}
# | 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... |