Submission #937322

#TimeUsernameProblemLanguageResultExecution timeMemory
937322snpmrnhlolAncient Books (IOI17_books)C++17
50 / 100
82 ms22784 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 1e6; const ll inf = 1e18; ll ps[N + 1]; long long minimum_walk(std::vector<int> p, int s) { int n = p.size(); ll ans = 0; ll mx = -inf; ll mn = inf; ll mx2 = -inf; ll mn2 = inf; bool ok = 0; for(ll i = 0;i < n;i++){ ans+=abs(i - p[i]); if(i != p[i]){ ok = 1; if(i < p[i]){ ps[p[i]]--; ps[i]++; } if(i <= s){ mx = max(mx,i); } if(i >= s){ mn = min(mn,i); } mx2 = max(mx2,i); mn2 = min(mn2,i); } } if(ok == 0)return ans; ll sum = 0; for(int i = mn2;i < mx2;i++){ sum+=ps[i]; //cout<<ps[i]<<' '; if(sum == 0)ans+=2; } ans+=2*min(s - mx,mn - s); return ans; } /** 4 0 3 2 1 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...