Submission #827758

#TimeUsernameProblemLanguageResultExecution timeMemory
827758Minindu206Ancient Books (IOI17_books)C++14
50 / 100
116 ms22632 KiB
#include "books.h" #include<bits/stdc++.h> #define ll long long using namespace std; ll minimum_walk(vector<int> p, int s) { ll res = 0; int n = p.size(); vector<ll> pref(n, 0LL); for(int i=0;i<n;i++) { res += abs(i - p[i]); pref[max(i, p[i])]--; pref[min(i, p[i])]++; } ll sub = 0; n--; while(p[n] == n) { if(n < 0) break; n--; } for(int i=0;i<n-1;i++) { if(i != 0) pref[i] += pref[i - 1]; if(pref[i] == 0) sub++; } return res + 2 * sub; }
#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...