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;
typedef vector<int> vi;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define pb push_back
long long minimum_walk(vi p, int s) {
long long ans = 0;
int maxi = 0;
int n = p.size();
vi used(n);
FOR(i, 0, n){
if (used[i]) continue;
maxi = max(maxi, i);
int cur = i; used[i] = 1;
while (p[cur] != i){
ans += abs(p[cur] - cur);
cur = p[cur];
used[cur] = 1;
}
ans += abs(i-cur);
}
ans += maxi*2;
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... |