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 sc second
#define fr first
#define mk make_pair
#define pb push_back
using namespace std;
const int N = (1e6 + 5);
const int inf = (1e9 + 7);
int a[N];
int n;
long long ans;
long long minimum_walk(vector<int> p, int s) {
n = p.size();
s ++;
for (int i = 0; i < n; i ++) a[i + 1] = p[i] + 1,ans += abs(p[i] - i);
int last = s;
for (int i = 1; i <= n; i ++) {
if (a[i] > i) {
if (i > 1 && a[i - 1] > a[i]) continue;
ans += abs(last - i);
last = a[i];
}
}
for (int i = n; i >= 1; i --) {
if (i > a[i]) {
ans += abs(last - i);
last = a[i];
}
}
return (ans + abs(s - last));
}
# | 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... |