# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
62626 | Tenuun | Ancient Books (IOI17_books) | C++17 | 4 ms | 792 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>
using namespace std;
bool vis[1000001]={false};
long long res=0, k;
vector<int>v;
void dfs(int u){
vis[u]=true;
res+=abs(v[u]-u);
if(v[u]==k) return;
dfs(v[u]);
}
long long minimum_walk(std::vector<int> p, int s) {
int last=0;
v=p;
for(int i=0; i<p.size(); i++){
if(i==p[i]) vis[i]=true;
}
for(int i=0; i<p.size(); i++){
if(vis[i]) continue;
res+=i-last;
k=i;
dfs(i);
last=i;
}
return res+last;
}
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... |