#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,tuple<int,int,int> >
const int N = 20000;
int n;
map<int,vector<int> > ma;
map<vector<int>,int> mb;
int res[N][5][5];
priority_queue<pii,vector<pii>,greater<pii> > q;
bool visited[N][5][5];
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 < N;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:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
33 | auto [per,id,hn] = q.top().second;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2560 KB |
Output is correct |
2 |
Correct |
3 ms |
2432 KB |
Output is correct |
3 |
Correct |
3 ms |
2432 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2432 KB |
3rd lines differ - on the 1st token, expected: '4', found: '2147483647' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2560 KB |
Output is correct |
2 |
Correct |
3 ms |
2432 KB |
Output is correct |
3 |
Correct |
3 ms |
2432 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2432 KB |
3rd lines differ - on the 1st token, expected: '4', found: '2147483647' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2560 KB |
Output is correct |
2 |
Correct |
3 ms |
2432 KB |
Output is correct |
3 |
Correct |
3 ms |
2432 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2432 KB |
3rd lines differ - on the 1st token, expected: '4', found: '2147483647' |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
2432 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2147483647' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2560 KB |
Output is correct |
2 |
Correct |
3 ms |
2432 KB |
Output is correct |
3 |
Correct |
3 ms |
2432 KB |
Output is correct |
4 |
Incorrect |
2 ms |
2432 KB |
3rd lines differ - on the 1st token, expected: '4', found: '2147483647' |
5 |
Halted |
0 ms |
0 KB |
- |