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;
const int nmax=1e6+42;
int go_left[nmax],go_right[nmax];
long long minimum_walk(std::vector<int> p, int s)
{
int n=p.size();
int maxi=0;
for(int i=0;i<n;i++)
if(i!=p[i])
{
maxi=max(maxi,i);
maxi=max(maxi,p[i]);
if(i<p[i])go_left[i]++,go_left[p[i]]--;
else go_right[p[i]]++,go_right[i]--;
}
for(int i=1;i<n;i++)
{
go_left[i]+=go_left[i-1];
go_right[i]+=go_right[i-1];
}
long long outp=0;
for(int i=0;i<maxi;i++)
{
//cout<<i<<" -> "<<go_left[i]<<" "<<go_right[i]<<endl;
if(go_left[i]==0&&go_right[i]==0)outp+=2;
else outp+=2*max(go_left[i],go_right[i]);
}
return outp;
}
# | 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... |