Submission #906780

#TimeUsernameProblemLanguageResultExecution timeMemory
906780nightfalAncient Books (IOI17_books)C++14
50 / 100
103 ms14676 KiB
#include <cstdio> #include <vector> #include <cassert> #include <cstdlib> using namespace std; long long minimum_walk(std::vector<int> p, int s) { int n = p.size(), last = 0; long long total = 0; for(int i=0; i<n; i++) { if (i==p[i]) continue; if(i>last) total += (i-last)*2; total += abs(p[i]-i); last = max(last,i); int idx = p[i]; p[i] = i; while(idx!=i) { last = max(last,idx); total += abs(p[idx]-idx); int prevIdx = idx; idx = p[idx]; p[prevIdx] = prevIdx; } } return total; }
#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...