Submission #172509

#TimeUsernameProblemLanguageResultExecution timeMemory
172509Mamnoon_SiamAncient Books (IOI17_books)C++17
0 / 100
3 ms504 KiB
#include <bits/stdc++.h> using namespace std; #include "books.h" using ll = long long; long long minimum_walk(std::vector<int> p, int s) { int n = p.size(); assert(s == 0); ll ans = 0; vector<bool> vis(n); for(int i = 0; i < n; i++) { if(!vis[i]) { // cout << "starting from = " << i << endl; int beg = i; vis[i] = 1; int now = p[beg]; ans += abs(beg - now); while(now != beg) { // cout << "\tnow = " << now << endl; ans += abs(now - p[now]); vis[now] = 1; now = p[now]; } ans += 2; } } for(int i = n-1; i >= n; i++) { if(p[i] != i) break; ans -= 2; } return ans - 2; return 69; }
#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...