Submission #1076044

#TimeUsernameProblemLanguageResultExecution timeMemory
1076044mdn2002Ancient Books (IOI17_books)C++17
0 / 100
1 ms348 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; long long minimum_walk(std::vector<int> p, int s) { assert(s == 0); long long ans = 0, n = p.size(), last = 0; for (int i = 0; i < n; i ++) { if (p[i] != i) { ans += abs(last - i); last = i; int carry = p[i], j = i; while (p[i] != i) { ans += abs(carry - p[carry]); swap(p[carry], carry); } } } ans += last; return ans; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:12:31: warning: unused variable 'j' [-Wunused-variable]
   12 |             int carry = p[i], j = 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...