Submission #612137

#TimeUsernameProblemLanguageResultExecution timeMemory
612137ShithilaAncient Books (IOI17_books)C++14
0 / 100
1 ms212 KiB
#include "books.h" #include<bits/stdc++.h> long long minimum_walk(std::vector<int> p, int s) { int len=p.size(); long long ans=0; int max=len-1; int pos[len]; for(int i=0;i<len;i++) { pos[p[i]]=i; } while(pos[max]==max) { max=max-1; if(max==0) { return ans; } } int i=0; int carrying=p[0]; //cout<<"aa"<<endl; while(p[i]!=-1) { if(pos[max]==max) { max--; continue; } ans=ans+abs(pos[max]-i); p[pos[max]]=carrying; pos[carrying]=pos[max]; if(i==0) { p[i]=-1; } else p[i]=carrying; i=pos[max]; ans=ans+abs(max-i); carrying=p[max]; i=max; pos[i]=max; max--; //cout<<i<<" "<<p[i]<<endl; } return ans; }
#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...