#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,tuple<int,int,int> >
const int N = 5;
const int M = 200;
int n;
map<int,vector<int> > ma;
map<vector<int>,int> mb;
int res[M][N][N];
priority_queue<pii,vector<pii>,greater<pii> > q;
bool visited[M][M][N];
long long minimum_walk(std::vector<int> p, int s)
{
n = 4;
vector<int> v;
for(int i = 0;i < n;i++) v.push_back(i);
int cnt = 0;
for(int i = 0;i <= 4;i++) for(int j = 0;j <= 4;j++) for(int k = 0;k <= 4;k++) for(int l = 0;l <= 4;l++)
{
vector<int> v = {i,j,k,l};
ma[cnt] = v;
mb[v] = cnt;
cnt++;
}
for(int i = 0;i < M;i++) for(int j = 0;j < n;j++) for(int k = 0;k <= n;k++) res[i][j][k] = INT_MAX;
res[mb[p]][s][4] = 0;
q.push({0,{mb[p],s,4}});
while(!q.empty())
{
auto [per,id,hn] = q.top().second;
q.pop();
if(visited[per][id][hn]) continue;
visited[per][id][hn] = true;
vector<int> now = ma[per];
for(int i = 0;i < 4;i++) if(res[per][id][hn]+abs(id-i)<res[per][i][hn])
{
res[per][i][hn] = res[per][id][hn]+abs(id-i);
q.push({res[per][i][hn],{per,i,hn}});
}
vector<int> nx = now;
int hnd = nx[id];
nx[id] = hn;
if(res[per][id][hn]<res[mb[nx]][id][hnd])
{
res[mb[nx]][id][hnd] = res[per][id][hn];
q.push({res[mb[nx]][id][hnd],{mb[nx],id,hnd}});
}
}
return res[mb[{0,1,2,3}]][0][4];
}
Compilation message
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:34:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
34 | auto [per,id,hn] = q.top().second;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
768 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
768 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
768 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
768 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
768 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |