#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int NOT_VIS = 0;
const int CUR_VIS = 1;
const int VIS = 2;
map<pair<vector<int>, pair<int, int>>, pair<int, ll>> vis {};
inline ll recSolve(int pos, vector<int> vals, int carry) {
if (pos >= (int)vals.size() || pos < 0)
return 1e9;
if (vis[{vals, {pos, carry}}].first == CUR_VIS)
return 1e9;
if (vis[{vals, {pos, carry}}].first == VIS)
return vis[{vals, {pos, carry}}].second;
ll mnAns = 1e9;
bool ok = true;
for (int i = 0; i < (int)vals.size(); i++)
if (vals[i] != i)
ok = false;
if (ok) {
//printf("food bruh %d %d\n", pos);
vis[{vals, {pos, carry}}] = {VIS, pos};
return pos;
}
vis[{vals, {pos, carry}}] = {CUR_VIS, 1e9};
mnAns = min(mnAns, 1 + recSolve(pos + 1, vals, carry));
mnAns = min(mnAns, 1 + recSolve(pos - 1, vals, carry));
swap(carry, val[pos])
mnAns = min(mnAns, recSolve(pos, vals, carry));
swap(carry, val[pos]);
vis[{vals, {pos, carry}}] = {VIS, mnAns};
return mnAns;
}
ll minimum_walk(vector<int> p, int s) {
int n = (int)p.size();
return recSolve(0, p, -1);
}
Compilation message
books.cpp: In function 'long long int recSolve(int, std::vector<int>, int)':
books.cpp:35:14: error: 'val' was not declared in this scope; did you mean 'vals'?
35 | swap(carry, val[pos])
| ^~~
| vals
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:43:9: warning: unused variable 'n' [-Wunused-variable]
43 | int n = (int)p.size();
| ^