Submission #1076182

#TimeUsernameProblemLanguageResultExecution timeMemory
1076182NeroZeinAncient Books (IOI17_books)C++17
50 / 100
587 ms38516 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; long long minimum_walk(vector<int> p, int s) { int n = (int) p.size(); set<int> se; long long ans = 0; vector<bool> b(n); for (int i = 0; i < n; i++) { ans += abs(i - p[i]); se.insert(p[i]); if (se.count(i)) { se.erase(i); } if (se.size() == 0 || *se.rbegin() <= i) { b[i] = 1; } } bool f = 0; for (int i = n - 1; i >= 0; i--) { if (f && b[i]) { ans += 2; } if (p[i] != i) { f = 1; } } 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...