Submission #152514

#TimeUsernameProblemLanguageResultExecution timeMemory
152514groeneprofAncient Books (IOI17_books)C++14
50 / 100
164 ms15028 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; long long minimum_walk(vector<int> p, int s) { int i = s; int j = s-1;//incl-incl int mi = s, ma=s; int n = p.size(); long long cnt = 0; while(i!=0||j!=n-1){ bool bol = false; while(mi < i){ bol = true; i--; mi = min(mi, p[i]); ma = max(ma, p[i]); } while(j<ma){ bol = true; j++; mi = min(mi, p[j]); ma = max(ma, p[j]); } if(!bol){ cnt+=2; //cout<<mi<<" "<<ma<<endl; if(mi>0){mi--;} if(ma<n-1){ma++;} } } for(int k = 0; k<s&&p[k]==k; k++) cnt-=2; for(int k = n-1; k>s&&p[k]==k; k--) cnt-=2; //cout<<cnt<<endl; for(int ii = 0; ii<n; ii++){ cnt += abs(ii - p[ii]); } return cnt; }
#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...