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;
typedef long long ll;
const int N = 1000000;
bool vis[N];
long long minimum_walk(std::vector<int> p, int s) {
ll res = 0;
int n = p.size();
for (int i = 0; i < n; i++)
{
if (p[i] == i || vis[i]) continue;
int cur = i;
do
{
vis[cur] = true;
res += abs(p[cur] - cur);
cur = p[cur];
} while (cur != i);
}
bool found = false;
for (int i = n - 1; i >= 0; i--)
{
if (vis[i]) found = true;
if (found && !vis[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... |