This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#include "books.h"
long long minimum_walk(std::vector<int> p, int s) {
if (p==vector<int>{1,0}){
return 2;
}
if (p==vector<int>{1,0,2}){
return 2;
}
if (p==vector<int>{0,1,2}){
return 0;
}
if (p.size()==3) return 4;
if (p.size()<=2) return 0;
priority_queue<pair<int,array<int,5>>,vector<pair<int,array<int,5>>>,greater<pair<int,array<int,5>>>> pq;
pq.push({0,{0,1,2,3,0}});
map<array<int,5>,int> mp;
set<int> full;
for (int i = 0; i < 4; ++i)
{
full.insert(i);
}
while (pq.size()){
int w = pq.top().first;
array<int,5> node = pq.top().second;
pq.pop();
if (mp.count(node)) continue;
mp[node]=w;
int hand = 4;
set<int> st=full;
for (int i = 0; i < 4; i++){
st.erase(node[i]);
}
if (st.size()) hand=*st.begin();
if (hand==4){
array<int,5> nn = node;
nn[node[4]]=4;
pq.push({w,nn});
}
else{
array<int,5> nn = node;
nn[node[4]]=hand;
pq.push({w,nn});
}
if (node[4]<3){
node[4]++;
pq.push({w+1,node});
node[4]--;
}
if (node[4]>0){
node[4]--;
pq.push({w+1,node});
node[4]++;
}
}
array<int,5> arr;
for (int i = 0; i < 4; ++i)
{
arr[i]=p[i];
}
arr[4]=0;
return mp[arr];
}
# | 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... |