Submission #1073841

#TimeUsernameProblemLanguageResultExecution timeMemory
1073841ArthuroWichAncient Books (IOI17_books)C++17
0 / 100
0 ms348 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; long long minimum_walk(vector<int> p, int s) { int ans = 0, n = p.size(); int i = 0; while(i < n) { if (p[i] == i) { i++; if (i != n) { ans++; } continue; } int a = i; while(p[a] != a) { ans += abs(p[a]-a); int b = p[a]; p[a] = a; a = b; } if (is_sorted(p.begin(), p.end())) { break; } i = a; i++; if (i != n) { ans++; } } if (i == n) { i--; } while(i >= 0) { if (p[i] == i) { i--; if (i < 0) { ans++; } continue; } int a = i; while(p[a] != a) { ans += abs(p[a]-a); int b = p[a]; p[a] = a; a = b; } i = a; i--; if (i < 0) { ans++; } } return ans; }
#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...