Submission #584528

#TimeUsernameProblemLanguageResultExecution timeMemory
584528PiejanVDCAncient Books (IOI17_books)C++17
0 / 100
1 ms300 KiB
#include <bits/stdc++.h> //#include "books.h" using namespace std; long long minimum_walk(vector<int>p, int s) { int n = p.size(); vector<int>v(n); for(int i = 0 ; i < n ; i++) v[i] = i; int last = 0; long long ans = 0; for(int i = 0 ; i < n ; i++) { if(i != p[v[i]]) { last = i; int pos = i; int save = v[i]; do { int nx = p[save]; ans += abs(nx - pos); swap(save, v[p[save]]); pos = nx; } while(pos != 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...