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 <vector>
#include <iostream>
#include <cmath>
#include <set>
#define int long long
using namespace std;
int minimum_walk(vector<signed> p, signed s)
{
int n = p.size();
int res = 0;
for (int i = 0; i < n; i++)
{
res += abs(i - p[i]);
}
set<int> numbers;
vector<bool> used(n - 1, 0);
for (int i = 0; i < n; i++)
{
if (numbers.size() > 0 && i > 0)
{
used[i - 1] = true;
}
numbers.erase(i);
if (p[i] > i) numbers.insert(p[i]);
}
bool nont = false;
for (int i = n - 1; i > 0; i--)
{
if (p[i] != i) nont = true;
if (!nont) used[i - 1] = true;
}
for (int i = 0; i < n - 1; i++)
{
if (!used[i]) res += 2;
}
return res;
}
# | 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... |