Submission #610278

#TimeUsernameProblemLanguageResultExecution timeMemory
610278PiejanVDCAncient Books (IOI17_books)C++17
50 / 100
147 ms10644 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; long long minimum_walk(vector<int>p, int s) { int n = p.size(); long long ans = 0; vector<bool>vis(n,0); int mx = 0; for(int i = 0 ; i < n ; i++) if(!vis[i] && p[i] != i) { vis[i] = 1; if(i > mx && p[i] != i) ans += 2*(i-mx); int pos = i; do { vis[pos] = 1; mx = max(mx, pos); int nxt = p[pos]; ans += abs(nxt-pos); pos = nxt; } while(pos != i); } 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...