Submission #135203

#TimeUsernameProblemLanguageResultExecution timeMemory
135203anaykAncient Books (IOI17_books)C++14
0 / 100
2 ms376 KiB
#include <iostream> #include "books.h" int min, max; int l, r; int n; void add(int val) { min = std::min(min, val); max = std::max(max, val); } long long minimum_walk(std::vector<int> p, int s) { n = p.size(); long long answer = 0; for(int i = 0; i < p.size(); i++) answer += (long long) abs(i-p[i]); min = max = l = r = s; add(p[s]); while(min > 0 || max < n-1) { if(l > min) { l--; add(p[l]); } else if(r < max) { r++; add(p[r]); } else { answer += 2; if(max < n-1) max++; else min--; } } return answer; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:20:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i++)
                 ~~^~~~~~~~~~
#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...