Submission #147889

#TimeUsernameProblemLanguageResultExecution timeMemory
147889HellAngelAncient Books (IOI17_books)C++14
0 / 100
3 ms380 KiB
#include <bits/stdc++.h> using namespace std; long long minimum_walk(vector<int> pos, int gau) { int n = pos.size(), Max = 0; long long ans = 0; for(int i = 0; i < n; i++) { if(pos[i] == i) continue; ans += i - Max; Max = max(Max, i); int p = pos[i], old = i; while(true) { ans += abs(p - old); if(p == i) break; int gau = pos[p]; old = p; pos[p] = p; p = gau; } } return ans + Max; }
#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...