Submission #915150

#TimeUsernameProblemLanguageResultExecution timeMemory
915150nightfalAncient Books (IOI17_books)C++14
50 / 100
91 ms12116 KiB
#include <cstdio> #include <vector> #include <cassert> #include <cstdlib> using namespace std; bool isSubtask3(int s) {return s==0;} long long subtask3(vector<int> p, int s, int dir = 1) { int n = p.size(), last = s; long long total = 0; for(int i=s; 0<=i && i<n; i += dir) { if (i==p[i]) continue; if (dir*(i-last) > 0) total += abs(i-last)*2; total += abs(p[i]-i); last = dir==1? max(last,p[i]):min(last,p[i]); } return total; } long long minimum_walk(std::vector<int> p, int s) { return subtask3(p,0); }
#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...