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 <bits/stdc++.h>
#include "books.h"
using namespace std;
long long minimum_walk(vector<int> p, int s) {
int n = (int) p.size();
set<int> se;
long long ans = 0;
vector<bool> b(n);
for (int i = 0; i < n; i++) {
ans += abs(i - p[i]);
se.insert(p[i]);
if (se.count(i)) {
se.erase(i);
}
if (se.size() == 0 || *se.rbegin() <= i) {
b[i] = 1;
}
}
bool f = 0;
for (int i = n - 1; i >= 0; i--) {
if (f && b[i]) {
ans += 2;
}
if (p[i] != i) {
f = 1;
}
}
return ans;
}
# | 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... |