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>
#define ll long long
using namespace std;
ll minimum_walk(vector<int> p, int s) {
ll res = 0;
int n = p.size();
vector<ll> pref(n, 0LL);
for(int i=0;i<n;i++)
{
res += abs(i - p[i]);
pref[max(i, p[i])]--;
pref[min(i, p[i])]++;
}
ll sub = 0;
n--;
while(p[n] == n)
{
if(n < 0)
break;
n--;
}
for(int i=0;i<n-1;i++)
{
if(i != 0)
pref[i] += pref[i - 1];
if(pref[i] == 0)
sub++;
}
return res + 2 * sub;
}
# | 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... |