이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include<bits/stdc++.h>
long long minimum_walk(std::vector<int> p, int s) {
int len=p.size();
long long ans=0;
int max=len-1;
int pos[len];
for(int i=0;i<len;i++)
{
pos[p[i]]=i;
}
while(pos[max]==max)
{
max=max-1;
if(max==0)
{
return ans;
}
}
int i=0;
int carrying=p[0];
//cout<<"aa"<<endl;
while(p[i]!=-1)
{
if(pos[max]==max)
{
max--;
continue;
}
ans=ans+abs(pos[max]-i);
p[pos[max]]=carrying;
pos[carrying]=pos[max];
if(i==0)
{
p[i]=-1;
}
else p[i]=carrying;
i=pos[max];
ans=ans+abs(max-i);
carrying=p[max];
i=max;
pos[i]=max;
max--;
//cout<<i<<" "<<p[i]<<endl;
}
return ans;
}
# | 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... |