제출 #127056

#제출 시각아이디문제언어결과실행 시간메모리
127056chubyxdxd고대 책들 (IOI17_books)C++11
0 / 100
3 ms376 KiB
#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 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...