Submission #828327

#TimeUsernameProblemLanguageResultExecution timeMemory
828327tolbiAncient Books (IOI17_books)C++17
0 / 100
1 ms340 KiB
#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 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...