# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
423667 | Bill_00 | Ancient Books (IOI17_books) | C++14 | 242 ms | 23772 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>
#define ll long long
using namespace std;
ll p[1000005],ans,vis[1000005],mx;
void dfs(ll node){
ans+=(abs(node-p[node]));
vis[node]=1;
mx=max(node,mx);
if(vis[p[node]]) return;
dfs(p[node]);
}
long long minimum_walk(std::vector<int> P, int s){
for(ll i=0;i<P.size();i++) p[i]=P[i];
for(ll i=0;i<P.size();i++){
if(vis[i]==0 && i!=p[i]){
if(i>mx){
ans+=((i-mx)*2);
}
dfs(i);
}
}
return ans;
}
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... |