Submission #828352

#TimeUsernameProblemLanguageResultExecution timeMemory
828352tolbiAncient Books (IOI17_books)C++17
12 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #include "books.h" long long minimum_walk(std::vector<int> p, int s) { int n = p.size(); vector<bool> vis(n,false); long long ans = 0; int lel = -1; for (int i = 0; i < n; ++i) { if (vis[i]) continue; if (p[i]!=i){ if (lel==-1){ ans+=i*2; } else { ans+=(i-lel-1)*2; } lel=i; } int node = i; while (!vis[node]){ vis[node]=true; ans+=abs(node-p[node]); node=p[node]; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...