Submission #152807

#TimeUsernameProblemLanguageResultExecution timeMemory
152807mieszko11bAncient Books (IOI17_books)C++14
0 / 100
3 ms376 KiB
#include "books.h" #include <bits/stdc++.h> using ll = long long; using namespace std; int n; bool vis[1000007]; long long minimum_walk(std::vector<int> p, int s) { ll res = 0; n = p.size(); int maxd = 0; for(int i = 0 ; i < n ; i++) { if(vis[i]) continue; int w = i; int mind = 1e9; while(!vis[w]) { vis[w] = 1; mind = min(mind, abs(s - w)); res += abs(p[w] - w); w = p[w]; } maxd = max(maxd, mind); } res += maxd * 2; return res; }
#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...