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;
long long minimum_walk(vector<int> p, int s) {
int n = (int)p.size();
long long sum = 0;
for (int i = 0; i < n; i++)
sum += abs(p[i] - i);
int l = n - 1;
while (l && p[l] == l) l--;
vector<int> suf = p;
for (int i = n - 2; i >= 0; i--)
suf[i] = min(suf[i], suf[i + 1]);
while (suf[l] < l) l = suf[l];
return sum + 2 * l;
}
# | 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... |