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 tag[1000005];
int a[1000005];
long long int ans;
long long minimum_walk(std::vector<int> p, int s) {
long long int n=p.size(),ans=0;
int l=n+1,r=-1;
int c=0;
for(int i=0;i<n;i++)
{
ans+=abs(i-p[i]);
if(i<p[i])
{
c=1;
for(int j=i;j<p[i];j++)tag[j]=1;
l=min(i,l);
r=max(p[i]-1,r);
}
if(i>p[i])
{
c=1;
for(int j=p[i];j<i;j++)tag[j]=1;
l=min(p[i],l);
r=max(i-1,r);
}
}
for(int i=min(s,l);i<=max(s,r);i++)
{
if(tag[i]==0)ans+=2;
}
if(c==0)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... |