Submission #593993

#TimeUsernameProblemLanguageResultExecution timeMemory
593993AlperenTAncient Books (IOI17_books)C++17
50 / 100
114 ms15984 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; long long minimum_walk(vector<int> p, int s){ int n = p.size(); vector<long long> arr(n + 1); for(int i = 0; i < n; i++){ arr[min(i, p[i])]++; arr[max(i, p[i])]--; } for(int i = 1; i < n; i++) arr[i] += arr[i - 1]; int mn = n, mx = -1; for(int i = 0; i < n; i++) if(arr[i]) mn = min(mn, i), mx = max(mx, i); if(mx == -1) return 0; else return accumulate(arr.begin() + mn, arr.begin() + mx + 1, 0ll) + 2 * count(arr.begin() + mn, arr.begin() + mx + 1, 0) + min(2 * abs(s - mn), 2 * abs(s - mx)); return 0; }
#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...