Submission #71592

#TimeUsernameProblemLanguageResultExecution timeMemory
71592idan_izmirliAncient Books (IOI17_books)C++14
50 / 100
267 ms58988 KiB
#include "books.h" long long minimum_walk(std::vector<int> p, int s) { long long result=-2; int current_max=0; for(int i=0;i<p.size();i++) { if(p[i]<i) { result+=i-p[i]; } else { result+=p[i]-i; if(p[i]>current_max) { current_max=p[i]; } } if(current_max==i) { result+=2; } } for(int i=0;i<s;i++) { if(p[i]!=i) { break; } result-=2; } for(int i=p.size()-1;i>s;i--) { if(p[i]!=i) { break; } result-=2; } return result; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:6:15: 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...