Submission #906344

#TimeUsernameProblemLanguageResultExecution timeMemory
906344nightfalAncient Books (IOI17_books)C++14
0 / 100
0 ms504 KiB
#include <cstdio> #include <vector> #include <cassert> #include <cstdlib> using namespace std; #include <vector> long long minimum_walk(std::vector<int> p, int s) { int n = p.size(), total = 0, prevI = 0; std::vector<int> v(n,0); for(int i=0; i<n; i++) { if (i==p[i]) continue; total += i - prevI; // printf("i=%d, prevI=%d, i-prevI=%d, total=%d\n",i,prevI,i-prevI,total); prevI = i; total += abs(p[i]-i); // printf("i=%d, p[%d]=%d, abs(p[%d]-%d)=%d, total=%d\n",i,i,p[i],i,i,abs(p[i]-i),total); int idx=p[i]; p[i]=i; while(idx!=i) { total += abs(p[idx]-idx); int prevIdx = idx; idx = p[idx]; p[prevIdx] = prevIdx; // printf("prevIdx=%d, idx=%d, p[%d]=%d, abs(p[%d]-idx)=%d, total=%d\n",prevIdx,idx,idx,p[idx],idx,abs(p[idx]-idx),total); } // printf("prevIdx=%d, idx=%d, p[%d]=%d\n",prevIdx,idx,idx,p[idx],idx); } return total + prevI; }
#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...