Submission #105443

#TimeUsernameProblemLanguageResultExecution timeMemory
105443Alexa2001Ancient Books (IOI17_books)C++17
0 / 100
3 ms384 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; typedef long long ll; const int Nmax = 1e6 + 5; bool used[Nmax]; int mdl(int x) { return (x > 0 ? x : -x); } ll minimum_walk(vector<int> p, int s) { int n = p.size(); int i, last = 0; ll ans = 0; for(i=0; i<n; ++i) if(!used[i]) { int x = i; do { ans += mdl(x - p[x]); used[x] = 1; x = p[x]; } while(x != i); if(i != p[i]) last = i; } ans += 2 * last; 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...