이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include<vector>
#include<cstdlib>
#include<climits>
long long minimum_walk(std::vector<int> p, int s) {
if(s!=0)return -1;
std::vector<char> vs(p.size());
int max_cr=0;
long long sbookmove=0;
for(int i=p.size();i--;){
sbookmove+=std::abs(i-p[i]);
if(vs[i])continue;
int cr=INT_MAX; // closest to the right of s
for(int j=i;;){
vs[j]=true;
cr=std::min(cr,j);
j=p[j];
if(j==i)break;
}
if(p[i]!=i)
max_cr=std::max(max_cr,cr);
}
return sbookmove+2*max_cr;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |