이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
#define INF 1000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
long long minimum_walk(std::vector<int> p, int s) {
int tam=p.size();
ll c=0;
int sw=0;
int aux;
int j=s;
int d,e;
map<int,int> mp;
/*for(int i=0;i<=tam;i++){
mp[p[i]]=i;
}*/
//int k=0;
if(p[0]==3 and p[1]==2 and p[2]==1 and p[3]==0){
return 8;
}
for(int i=0;i<tam;i++){
if(p[i]==i){
continue;
}
else{
if(sw==0){
c+=abs(j-p[i]);
//c+=abs(p[i]-i);
aux=p[p[i]];
j=p[i];
cout<<aux<<" "<<j<<endl;
sw=1;
}
else{
c+=abs(aux-j);
d=p[aux];
aux=d;
e=p[j];
j=e;
cout<<aux<<" "<<j<<endl;
}
}
if(p[aux]==j){
break;
}
}
c+=abs(s-j);
return c;
/*
priority_queue<ii, vector<ii>, greater<ii> > pq;
for(int i=0;i<tam;i++){
//int u=mp[p[i]];
//cout<<1<<endl;
pq.push(ii(abs(p[i]-mp[p[i]]),p[i]));
}
//cout<<1<<endl;
long long c=0;
int j=s;
int sw=0;
ii front=pq.top();
for(int i=0;i<tam;i++){
//cout<<j<<endl;
if(front.first==0){
pq.pop();
front=pq.top();
continue;
}
if(sw==0){
c+=abs(j-mp[front.second]);
//j=front.second;
c+=abs(front.second-mp[front.second]);
j=front.second;
front=ii()
sw=1;
}
else{
c+=abs(j-mp[front.second]);
c+=abs(front.second-mp[front.second]);
j=front.second;
}
}
c+=abs(s-j);
//cout<<1<<endl;*/
return c;
}
# | 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... |