# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1048268 | LittleOrange | Ancient Books (IOI17_books) | C++17 | 0 ms | 0 KiB |
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;
using ll = long long;
long long minimum_walk(std::vector<int> p, int s) {
ll ans = 0;
ll n = p.size();
if (s == 0){
vector<ll> u(n,0);
for(ll i = 0;i<n;i++){
if(p[i]!=i){
ans += i-s;
s = i;
ll x = i;
do{
ans += ans(p[x]-x);
ll y = x;
x = p[x];
p[y] = y;
} while(x!=i);
}
}
}
return ans;
}