Language: C++

// ------ Includes ------ //
  
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <iostream>
  
using namespace std;
  
  
// ------ Directions ------ //
  
const int dx[4] = { 0, 1, 0, -1 };
const int dy[4] = { 1, 0, -1, 0 };
  
  
// ------ BFS ------ //
  
int BFS(vector<vector<int> > p)
{
    // ------ Initialize ------ //
  
    vector<vector<char> > lastboard = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 0 } };
  
    map<vector<vector<char> >, int> D;
  
    queue<pair<vector<vector<char> >, char> > que;
  
    D[p] = 1; que.push(make_pair(p, 1));
  
  
    // ------ Search ------ //
  
    if (p == lastboard)
    {
        return 0;
    }
  
    while (!que.empty())
    {
        pair<vector<vector<char> >, char> p1 = que.front(); que.pop();
  
  
        // ------ 0 Searching ------ //
  
        int tx = -1, ty = -1;
  
        for (int i = 0; i < p1.first.size(); i++)
        {
            for (int j = 0; j < p1.first[i].size(); j++)
            {
                if (p1.first[i][j] == 0)
                {
                    tx = j; ty = i;
                }
            }
        }
  
  
        // ------ Moving ------ //
  
        for (int dir = 0; dir < 4; dir++)
        {
            if (0 <= tx + dx[dir] && tx + dx[dir] < p1.first[0].size() && 0 <= ty + dy[dir] && ty + dy[dir] < p1.first.size())
            {
                vector<vector<char> > p2 = p1.first;
  
                swap(p2[ty][tx], p2[ty + dy[dir]][tx + dx[dir]]);
  
                if (D[p2] == 0)
                {
                    if (p2 == lastboard)
                    {
                        return p1.second;
                    }
  
                    D[p2] = p1.second + 1;
  
                    que.push(make_pair(p2, p1.second + 1));
                }
            }
        }
    }
  
    return -1;
}
  
int main()
{
    vector<vector<char> > board(4, vector<int>(4, -1)); int S;
  
    for (int i = 0; i < board.size(); i++)
    {
        for (int j = 0; j < board[i].size(); j++)
        {
            cin >> A;

            board[i][j] = A;
        }
    }
  
    cout << BFS(board) << endl;
  
    return 0;
}

Compiler output:
a.cc: In function 'int BFS(std::vector<std::vector<int> >)':
a.cc:30:6: error: no match for 'operator[]' (operand types are 'std::map<std::vector<std::vector<char> >, int>' and 'std::vector<std::vector<int> >')
   30 |     D[p] = 1; que.push(make_pair(p, 1));
      |      ^
In file included from /usr/include/c++/14/map:63,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_map.h:504:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::vector<std::vector<char> >; _Tp = int; _Compare = std::less<std::vector<std::vector<char> > >; _Alloc = std::allocator<std::pair<const std::vector<std::vector<char> >, int> >; mapped_type = int; key_type = std::vector<std::vector<char> >]'
  504 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:504:34: note:   no known conversion for argument 1 from 'std::vector<std::vector<int> >' to 'const std::map<std::vector<std::vector<char> >, int>::key_type&' {aka 'const std::vector<std::vector<char> >&'}
  504 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:524:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](key_type&&) [with _Key = std::vector<std::vector<char> >; _Tp = int; _Compare = std::less<std::vector<std::vector<char> > >; _Alloc = std::allocator<std::pair<const std::vector<std::vector<char> >, int> >; mapped_type = int; key_type = std::vector<std::vector<char> >]'
  524 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:524:29: note:   no known conversion for argument 1 from 'std::vector<std::vector<int> >' to 'std::map<std::vector<std::vector<char> >, int>::key_type&&' {aka 'std::vector<std::vector<char> >&&'}
  524 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
a.cc:30:23: error: no matching function for call to 'std::queue<std::pair<std::vector<std::vector<char> >, char> >::push(std::pair<std::vector<std::vector<int> >, int>)'
   30 |     D[p] = 1; que.push(make_pair(p, 1));
      |               ~~~~~~~~^~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_queue.h:283:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<std::vector<std::vector<char> >, char>; _Sequence = std::deque<std::pair<std::vector<std::vector<char> >, char>, std::allocator<std::pair<std::vector<std::vector<char> >, char> > >; value_type = std::pair<std::vector<std::vector<char> >, char>]'
  283 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:283:30: note:   no known conversion for argument 1 from 'std::pair<std::vector<std::vector<int> >, int>' to 'const std::queue<std::pair<std::vector<std::vector<char> >, char> >::value_type&' {aka 'const std::pair<std::vector<std::vector<char> >, char>&'}
  283 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:288:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(value_type&&) [with _Tp = std::pair<std::vector<std::vector<char> >, char>; _Sequence = std::deque<std::pair<std::vector<std::vector<char> >, char>, std::allocator<std::pair<std::vector<std::vector<char> >, char> > >; value_type = std::pair<std::vector<std::vector<char> >, char>]'
  288 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:288:25: note:   no known conversion for argument 1 from 'std::pair<std::vector<std::vector<int> >, int>' to 'std::queue<std::pair<std::vector<std::vector<char> >, char> >::value_type&&' {aka 'std::pair<std::vector<std::vector<char> >, char>&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:35:11: error: no match for 'operator==' (operand types are 'std::vector<std::vector<int> >' and 'std::vector<std::vector<char> >')
   35 |     if (p == lastboard)
      |         ~ ^~ ~~~~~~~~~
      |         |    |
      |         |    vector<vector<char>>
      |         vector<vector<int>>
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/bits/stl_tree.h:63,
                 from /usr/include/c++/14/map:62:
/usr/include/c++/14/bits/stl_pair.h:1033:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator==(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1033 |     operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1033:5: note:   template argument deduction/substitution failed:
a.cc:35:14: note:   'std::vector<std::vector<int> >' is not derived from 'const std::pair<_T1, _T2>'
   35 |     if (p == lastboard)
      |              ^~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:441:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  441 |     operator==(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:441:5: note:   template argument deduction/substitution failed:
a.cc:35:14: note:   'std::vector<std::vector<int> >' is not derived from 'const std::reverse_iterator<_Iterator>'
   35 |     if (p == lastboard)
      |              ^~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:486:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  486 |     operator==(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:486:5: note:   template argument deduction/substitution failed:
a.cc:35:14: note:   'std::vector<std::vector<int> >' is not derived from 'const std::reverse_iterator<_Iterator>'
   35 |     if (p == lastboard)
      |              ^~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1667:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1667 |     operator==(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1667:5: note:   template argument deduction/substitution failed:
a.cc:35:14: note:   'std::vector<std::vector<int> >' is not derived from 'const std::move_iterator<_IteratorL>'
   35 |     if (p == lastboard)
      |              ^~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1737:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1737 |     operator==(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1737:5: note:   template argument deduction/substitution failed:
a.cc:35:14: note:   'std::vector<std::vector<int> >' is not derived from 'const std::move_iterator<_IteratorL>'
   35 |     if (p == lastboard)
      |              ^~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_tree.h:64:
/usr/include/c++/14/bits/allocator.h:235:5: note: candidate: 'template<class _T1, class _T2> bool std::operator==(const allocator<_Tp1>&, const allocator<_T2>&)'
  235 |     operator==(const allocator<_T1>&, const allocator<_T2>&)
      |     ^~~~~~~~
/usr/include/c++/14/bits/allocator.h:235:5: note:   template argument deduction/substitution failed:
a.cc:35:14: note:   'std::vector<std::vector<int> >' is not derived from 'const std::allocator<_Tp1>'
   35 |     if (p == lastboard)
      |              ^~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_map.h:63:
/usr/include/c++/14/tuple:2558:5: note: candidate: 'template<class ... _TElements, class ... _UElements> constexpr bool std::operator==(const tuple<_Args1 ...>&, const tuple<_Elements ...>&)'
 2558 |     operator==(const tuple<_TElements...>& __t,
      |     ^~~~~~~~
/usr/include/c++/14/tuple:2558:5: note:   template argument deduction/substitution failed:
a.cc:35:14: note:   'std::vector<std::vector<int> >' is not derived from 'const std::tuple<_Args1 ...>'
   35 |     if (p == lastboard)
      |              ^~~~~~~~~
/usr/include/c++/14/bits/stl_map.h:1512:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const map<_Key, _Tp, _Compare, _Allocator>&, const map<_Key, _Tp, _Compare, _Allocator>&)'
 1512 |     operator==(const map<_Key, _Tp, _Compare, _Alloc>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_map.h:1512:5: note:   template argument deduction/substitution failed:
a.cc:35:14: note:   'std::vector<std::vector<int> >' is not derived from 'const std::map<_Key, _Tp, _Compare, _Allocator>'
   35 |     if (p == lastboard)
      |              ^~~~~~~~~
In file included from /usr/include/c++/14/map:64:
/usr/include/c++/14/bits/stl_multimap.h:1134:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> bool std::operator==(const multimap<_Key, _Tp, _Compare, _Allocator>&, const multimap<_Key, _Tp, _Compare, _Allocator>&)'
 1134 |     operator==(const multimap<_Key, _Tp, _Compare, _Alloc>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_multimap.h:1134:5: note:   template argument deduction/substitution failed:
a.cc:35:14: note:   'std::vector<std::vector<int> >' is not derived from 'const std::multimap<_Key, _Tp, _Compare, _Allocator>'
   35 |     if (p == lastboard)
      |              ^~~~~~~~~
In file included from /usr/include/c++/14/deque:66,
                 from /usr/include/c++/14/queue:62:
/usr/include/c++/14/bits/stl_deque.h:2294:5: note: candidate: 'template<class _Tp, class _Alloc> bool std::operator==(const deque<_Tp, _Alloc>&, const deque<_Tp, _Alloc>&)'
 2294 |     operator==(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_deque.h:2294:5: note:   template argument deduction/