Submission #906376

#TimeUsernameProblemLanguageResultExecution timeMemory
906376nightfalAncient Books (IOI17_books)C++14
12 / 100
1 ms600 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); // 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); last = max(i,p[i]); int idx = p[i]; p[i] = i; // printf("idx=%d, p[%d]=%d\n",idx,i,p[i]); while(idx!=i) { last = max(last,idx); total += abs(p[idx]-idx); // printf("idx=%d, p[%d]=%d, abs(p[%d]-%d)=%d, total=%d\n",idx,idx,p[idx],idx,idx,abs(p[idx]-idx),total); int prevIdx = idx; idx = p[idx]; p[prevIdx] = prevIdx; // printf("prevIdx=%d, p[%d]=%d, idx=%d\n", prevIdx, prevIdx, p[prevIdx], idx); } } 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...