Submission #767664

#TimeUsernameProblemLanguageResultExecution timeMemory
767664SanguineChameleonAncient Books (IOI17_books)C++17
0 / 100
1 ms304 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]) { int sz = 0; int cur = i; while (true) { sz++; flag[cur] = true; res += abs(cur - p[cur]); cur = p[cur]; if (cur == i) { break; } } if (sz >= 2) { mx = max(mx, i); } } } 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...