Submission #767641

#TimeUsernameProblemLanguageResultExecution timeMemory
767641SanguineChameleonAncient Books (IOI17_books)C++17
0 / 100
1 ms212 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; long long minimum_walk(vector<int> p, int s) { int n = p.size(); vector<bool> flag(n); long long res = 0; int mx = 0; for (int i = 0; i < n; i++) { if (!flag[i]) { mx = max(mx, i); int cur = i; while (true) { flag[cur] = true; res += abs(cur - p[cur]); cur = p[cur]; if (cur == i) { break; } } } } res += mx * 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...