Submission #71215

#TimeUsernameProblemLanguageResultExecution timeMemory
71215KmcodeAncient Books (IOI17_books)C++14
50 / 100
256 ms16336 KiB
#include<bits/stdc++.h> //#include "books.h" using namespace std; int im1[1000002]; int im2[1000002]; long long minimum_walk(std::vector<int> p, int s) { for(int i=0;i<p.size();i++){ if(i<=p[i]){ im1[i]++; im1[p[i]]--; } else{ im2[p[i]]++; im2[i]--; } } for(int i=1;i<p.size();i++){ im1[i]+=im1[i-1]; im2[i]+=im2[i-1]; } int ava=0; long long int turn=0; for(int i=p.size()-1;i>=s;i--){ if(im1[i]||im2[i]){ ava=1; } int need=max(im1[i],im2[i]); need*=2; need=max(need,ava*2); turn+=need; } ava=0; for(int i=0;i<s;i++){ if(im1[i]||im2[i]){ ava=1; } int need=max(im1[i],im2[i]); need*=2; need=max(need,ava*2); turn+=need; } return turn; }

Compilation message (stderr)

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