Submission #776082

#TimeUsernameProblemLanguageResultExecution timeMemory
776082petezaAncient Books (IOI17_books)C++14
50 / 100
93 ms15912 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; int qs[1000005], cval[1000005]; long long minimum_walk(std::vector<int> p, int s) { int cur = 0, cv = 0, curcnt = 0; long long cans = 0; for(int i=0;i<=p.size();i++) qs[i] = 0; for(int i=0;i<p.size();i++) { qs[min(i, p[i])]++; qs[max(i, p[i])]--; } for(int i=0;i<p.size();i++) { cv += qs[i]; cans += cv; cval[i] = cv; if(!cv) cur++; } int corner = 0; for(int i=0;i<min((int)p.size(), s);i++) { if(cval[i] != 0) break; corner++; } for(int i=p.size()-1;i>=s;i--) { if(cval[i] != 0) break; corner++; } return cans + 2*(cur-corner); }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:9:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for(int i=0;i<=p.size();i++) qs[i] = 0;
      |                 ~^~~~~~~~~~
books.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i=0;i<p.size();i++) {
      |                 ~^~~~~~~~~
books.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0;i<p.size();i++) {
      |                 ~^~~~~~~~~
books.cpp:7:26: warning: unused variable 'curcnt' [-Wunused-variable]
    7 |     int cur = 0, cv = 0, curcnt = 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...