이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
int where[nmax];
bool been[nmax];
long long minimum_walk(vector<int> p, int s)
{
int n=p.size();
for(int i=0;i<n;i++)
where[i]=p[i];
long long ans=0;
int last=0;
for(int i=0;i<n;i++)
if(been[i]==0)
{
ans=ans+i-last;
last=i;
int now=i;
while(been[now]==0)
{
ans=ans+abs(now-where[now]);
been[now]=1;
now=where[now];
}
}
return ans+last;
}
/*
int main()
{
cout<<minimum_walk({0, 2, 3, 1}, 0)<<endl;
return 0;
}
*/
| # | 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... |