# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
775871 | 2023-07-07T05:40:28 Z | PoonYaPat | Ancient Books (IOI17_books) | C++14 | 0 ms | 0 KB |
#include "books.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans=0,cnt[1000005]; ll minimum_walk(vector<int> p, int s) { int n=p.size(); for (int i=0; i<n; ++i) { ++cnt[min(i,p[i])]; --cnt[max(i,p[i])]; } for (int i=1; i<n; ++i) cnt[i]+=cnt[i-1]; int s=0; for (int i=0; i<n-1; ++i) { ans+=cnt[i]; if (cnt[i]==0) ++s; else ans+=2*s, s=0; } return ans; }