Submission #286877

#TimeUsernameProblemLanguageResultExecution timeMemory
286877tmwilliamlin168Ancient Books (IOI17_books)C++14
50 / 100
196 ms18936 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; #define ll long long ll minimum_walk(vector<int> p, int s) { int n=p.size(); ll ans=0; vector<int> a(n); for(int i=0; i<n; ++i) { ans+=abs(i-p[i]); ++a[min(i, p[i])]; --a[max(i, p[i])]; } for(int i=0; i+1<n; ++i) { a[i+1]+=a[i]; ans+=2*!a[i]; } for(int i=n-2; ~i&&!a[i]; --i) ans-=2*!a[i]; 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...