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;
long long minimum_walk(vector<int> p, int s) {
int ans = 0, n = p.size();
int i = 0;
while(i < n) {
if (p[i] == i) {
i++;
if (i != n) {
ans++;
}
continue;
}
int a = i;
while(p[a] != a) {
ans += abs(p[a]-a);
int b = p[a];
p[a] = a;
a = b;
}
if (is_sorted(p.begin(), p.end())) {
break;
}
i = a;
i++;
if (i != n) {
ans++;
}
}
if (i == n) {
i--;
}
while(i >= 0) {
if (p[i] == i) {
i--;
if (i < 0) {
ans++;
}
continue;
}
int a = i;
while(p[a] != a) {
ans += abs(p[a]-a);
int b = p[a];
p[a] = a;
a = b;
}
i = a;
i--;
if (i < 0) {
ans++;
}
}
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... |