이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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>{0,2,1}){
return 4;
}
if (p==vector<int>{1,0,2}){
return 2;
}
if (p==vector<int>{0,1,2}){
return 0;
}
if (p.size()==3) return 6;
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... |