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;
bool vis[1005];
long long minimum_walk(vector<int> p, int s) {
int n=p.size();
long long ans=0;
for(int i=0;i<n;i++){
ans+=abs(i-p[i]);
for(int j=min(i,p[i])+1;j<=max(i,p[i]);j++){
vis[j]=true;
}
}
int k=-1;
for(int i=n-1;i>=0;i--){
if(p[i]!=i){
k=i;
break;
}
}
k++;
for(int i=1;i<k;i++){
if(!vis[i]){
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... |