Submission #583416

#TimeUsernameProblemLanguageResultExecution timeMemory
583416InternetPerson10Ancient Books (IOI17_books)C++17
50 / 100
116 ms15072 KiB
#include "books.h" #include <bits/stdc++.h> typedef long long ll; using namespace std; long long minimum_walk(vector<int> p, int s) { ll ans = 0; int n = p.size(); int best = 0; vector<bool> taken(n, false); for(int i = 0; i < n; i++) { if(p[i] == i) continue; if(best < i) { ans += 2 * (i - best); } if(!taken[i]) { int x = i; while(!taken[x]) { best = max(x, best); taken[x] = true; ans += abs(x - p[x]); x = p[x]; } } } 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...