# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
420722 | EJOI2019Andrew | Ancient Books (IOI17_books) | C++14 | 0 ms | 0 KiB |
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"
long long minimum_walk(std::vector<int> p, int s) {
map<int,int>v;
int n=p.size();
long long int a(0);
int c(0);
for(int i=0;i<n;++i)
{
a+=abs(i-p[i]);
for(int j=min(i,p[i]);j<max(i,p[i]);++j)
v[j]=1;
}
for(int i=0;i<n;++i)
{
if(!v[i])
++c;
else
{
a+=2*c;
c=0;
}
}
return a;
}