Submission #1048537

#TimeUsernameProblemLanguageResultExecution timeMemory
1048537Gromp15Ancient Books (IOI17_books)C++17
0 / 100
0 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 lst = 0; for (int i = 0; i < n; i++) if (!vis[i]) { ans += 2 * (i - lst); int tmp = i; long long cur = 0; while (!vis[tmp]) { cur += abs(tmp - p[tmp]), vis[tmp] = 1, tmp = p[tmp]; } lst = tmp; ans += cur; } 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...