제출 #152520

#제출 시각아이디문제언어결과실행 시간메모리
152520groeneprof고대 책들 (IOI17_books)C++14
50 / 100
176 ms8520 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; int b = 0, e = n; for(int k = 0; k<s&&p[k]==k; k++) b = k+1; for(int k = n-1; k>s&&p[k]==k; k--) e = k; while(i>b||j<e-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>b){mi--;} if(ma<e-1){ma++;} } } //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...