Submission #775876

#TimeUsernameProblemLanguageResultExecution timeMemory
775876petezaAncient Books (IOI17_books)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> #include "books.h" long long minimum_walk(std::vector<int> p, int s) { int cur = 0; std::vector<bool> vis(p.size(), 0); long long cans = 0; for(int i=0;i<p.size();i++) { if(vis[i] || p[i] == i) continue; cur = i; int x = p[i]; vis[i] = 1; long long csum = llabs(i-p[i]); while(x != i) { vis[x] = 1; csum += llabs(x-p[x]); x = p[x]; } cans += csum; } return cans + 2*cur; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:8:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     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...