# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
775876 | peteza | Ancient Books (IOI17_books) | C++14 | 1 ms | 212 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 <bits/stdc++.h>
#include "books.h"
long long minimum_walk(std::vector<int> p, int s) {
int cur = 0;
std::vector<bool> vis(p.size(), 0);
long long cans = 0;
for(int i=0;i<p.size();i++) {
if(vis[i] || p[i] == i) continue;
cur = i;
int x = p[i]; vis[i] = 1;
long long csum = llabs(i-p[i]);
while(x != i) {
vis[x] = 1;
csum += llabs(x-p[x]);
x = p[x];
}
cans += csum;
}
return cans + 2*cur;
}
Compilation message (stderr)
# | 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... |