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>
#include "books.h"
using namespace std;
long long minimum_walk(vector<int> p, int s) {
int i = s;
int j = s-1;//incl-incl
int mi = s, ma=s;
int n = p.size();
long long cnt = 0;
while(i!=0||j!=n-1){
bool bol = false;
while(mi < i){
bol = true;
i--;
mi = min(mi, p[i]);
ma = max(ma, p[i]);
}
while(j<ma){
bol = true;
j++;
mi = min(mi, p[j]);
ma = max(ma, p[j]);
}
if(!bol){
cnt+=2;
//cout<<mi<<" "<<ma<<endl;
if(mi>0){mi--;}
if(ma<n-1){ma++;}
}
}
for(int k = 0; k<s&&p[k]==k; k++) cnt-=2;
for(int k = n-1; k>s&&p[k]==k; k--) cnt-=2;
//cout<<cnt<<endl;
for(int ii = 0; ii<n; ii++){
cnt += abs(ii - p[ii]);
}
return cnt;
}
# | 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... |