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>
using namespace std;
#include "books.h"
using ll = long long;
long long minimum_walk(std::vector<int> p, int s) {
int n = p.size();
assert(s == 0);
ll ans = 0;
vector<bool> vis(n);
for(int i = 0; i < n; i++) {
if(!vis[i]) {
// cout << "starting from = " << i << endl;
int beg = i;
vis[i] = 1;
int now = p[beg];
ans += abs(beg - now);
while(now != beg) {
// cout << "\tnow = " << now << endl;
ans += abs(now - p[now]);
vis[now] = 1;
now = p[now];
}
ans += 2;
}
}
for(int i = n-1; i >= n; i++) {
if(p[i] != i) break;
ans -= 2;
}
return ans - 2;
return 69;
}
# | 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... |