Submission #127023

#TimeUsernameProblemLanguageResultExecution timeMemory
127023chubyxdxdAncient Books (IOI17_books)C++11
0 / 100
2 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; for(int i=0;i<tam;i++){ if(p[i]==i){ continue; } else{ if(sw==0){ c+=abs(s-p[i]); c+=abs(p[i]-i); aux=p[p[i]]; j=p[i]; sw=1; } else{ c+=abs(aux-j); aux=p[p[i]]; j=p[i]; } } } //c+=abs(s-j); return c; /*map<int,int> mp; for(int i=0;i<tam;i++){ mp[p[i]]=i; } 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...