Submission #1048633

#TimeUsernameProblemLanguageResultExecution timeMemory
1048633Gromp15Ancient Books (IOI17_books)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; long long minimum_walk(std::vector<int> p, int s) { int n = p.size(); vector<bool> vis(n); long long ans = 0; int right = 0; for (int i = 0; i < n; i++) if (i != p[i] && !vis[i]) { right = max(right, i); int tmp = i; while (!vis[tmp]) { ans += abs(tmp - p[tmp]), vis[tmp] = 1, tmp = p[tmp]; } } return ans + 2 * right; }
#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...