Submission #165614

#TimeUsernameProblemLanguageResultExecution timeMemory
165614johuthaAncient Books (IOI17_books)C++14
50 / 100
631 ms20444 KiB
#include "books.h" #include <vector> #include <iostream> #include <cmath> #include <set> #define int long long using namespace std; int minimum_walk(vector<signed> p, signed s) { int n = p.size(); int res = 0; for (int i = 0; i < n; i++) { res += abs(i - p[i]); } set<int> numbers; vector<bool> used(n - 1, 0); for (int i = 0; i < n; i++) { if (numbers.size() > 0 && i > 0) { used[i - 1] = true; } numbers.erase(i); if (p[i] > i) numbers.insert(p[i]); } bool nont = false; for (int i = n - 1; i > 0; i--) { if (p[i] != i) nont = true; if (!nont) used[i - 1] = true; } for (int i = 0; i < n - 1; i++) { if (!used[i]) res += 2; } return res; }
#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...