Submission #1028886

#TimeUsernameProblemLanguageResultExecution timeMemory
1028886DorostWefAncient Books (IOI17_books)C++17
0 / 100
1 ms344 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100012; bool vis[N]; int n; long long minimum_walk(std::vector<int> p, int s) { long long ans = 0; n = (int)p.size(); for (int i = 0; i < n; i++) { ans += abs (p[i] - i); } int mx = 0; for (int i = 0; i < n; i++) { if (!vis[i]) { mx = i; int j = i; while (p[j] != i) { j = p[j]; vis[j] = true; } } } return ans + 2 * mx; }
#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...