Language: C++

#include<iostream>
#include<queue>
#include<cmath>
#include<functional>
#include<vector>
#include<algorithm>
using namespace std;
struct Puzzle {
	int x[4][4];
};
priority_queue<pair<int, Puzzle>, vector<pair<int, Puzzle>>, greater<pair<int, Puzzle>>>Q; Puzzle Z;
int manh(Puzzle y) {
	int sum = 0; pair<int, int> p[16];
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			p[y.x[i][j]] = make_pair(i, j);
		}
	}
	for (int i = 0; i < 16; i++) {
		int X = (i - 1) / 4, Y = (i - 1) % 4;
		if (i == 0) { X = 3; Y = 3; }
		sum += abs(X - p[i].first) + abs(Y - p[i].second);
	}
	return sum;
}
int main() {
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++) {
			cin >> Z.x[i][j];
		}
	}
	Q.push(make_pair(0, Z)); int cnt = 0;
	while (!Q.empty()) {
		Puzzle r = Q.top().second; cnt++;
		Puzzle s; int V = Q.top().first;
		pair<int, int>z; Q.pop();
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (r.x[i][j] == 0) z = make_pair(i, j);
			}
		}
		int dx[4] = { 0,1,0,-1 };
		int dy[4] = { 1,0,-1,0 };
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				for (int k = 0; k < 4; k++)s.x[j][k] = r.x[j][k];
			}
			int px = z.first + dx[i], py = z.second + dy[i];
			if (py < 0 || py > 3)continue;
			if (px < 0 || px > 3)continue;
			swap(s.x[z.first][z.second], s.x[px][py]);
			if (manh(r) >= manh(s)) {
				int OK = 1;
				for (int j = 0; j < 4; j++) {
					for (int k = 0; k < 4; k++) {
						if (s.x[j][k] != (j * 4 + k + 1) % 16) OK = 0;
					}
				}
				if (OK == 1) {
					cout << V + 1 << endl;
					//cout << cnt << endl;
					return 0;
				}
				Q.push(make_pair(V + 1, s));
			}
		}
	}
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h: In instantiation of 'constexpr bool std::operator<(const pair<_T1, _T2>&, const pair<_T1, _T2>&) [with _T1 = int; _T2 = Puzzle]':
/usr/include/c++/14/bits/stl_pair.h:1059:18:   required from 'constexpr bool std::operator>(const pair<_T1, _T2>&, const pair<_T1, _T2>&) [with _T1 = int; _T2 = Puzzle]'
 1059 |     { return __y < __x; }
      |              ~~~~^~~~~
/usr/include/c++/14/bits/stl_function.h:395:20:   required from 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = std::pair<int, Puzzle>]'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/predefined_ops.h:196:23:   required from 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = __gnu_cxx::__normal_iterator<std::pair<int, Puzzle>*, std::vector<std::pair<int, Puzzle> > >; _Value = std::pair<int, Puzzle>; _Compare = std::greater<std::pair<int, Puzzle> >]'
  196 |         { return bool(_M_comp(*__it, __val)); }
      |                       ~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:140:48:   required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<int, Puzzle>*, vector<pair<int, Puzzle> > >; _Distance = long int; _Tp = pair<int, Puzzle>; _Compare = __gnu_cxx::__ops::_Iter_comp_val<greater<pair<int, Puzzle> > >]'
  140 |       while (__holeIndex > __topIndex && __comp(__first + __parent, __value))
      |                                          ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_heap.h:216:23:   required from 'void std::push_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<pair<int, Puzzle>*, vector<pair<int, Puzzle> > >; _Compare = greater<pair<int, Puzzle> >]'
  216 |       std::__push_heap(__first, _DistanceType((__last - __first) - 1),
      |       ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217 |                        _DistanceType(0), _GLIBCXX_MOVE(__value), __cmp);
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:747:16:   required from 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = std::pair<int, Puzzle>; _Sequence = std::vector<std::pair<int, Puzzle> >; _Compare = std::greater<std::pair<int, Puzzle> >; value_type = std::pair<int, Puzzle>]'
  747 |         std::push_heap(c.begin(), c.end(), comp);
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:32:8:   required from here
   32 |         Q.push(make_pair(0, Z)); int cnt = 0;
      |         ~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1047:57: error: no match for 'operator<' (operand types are 'const Puzzle' and 'const Puzzle')
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:448:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  448 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:448:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:1047:57: note:   'const Puzzle' is not derived from 'const std::reverse_iterator<_Iterator>'
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  493 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:1047:57: note:   'const Puzzle' is not derived from 'const std::reverse_iterator<_Iterator>'
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1694 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:1047:57: note:   'const Puzzle' is not derived from 'const std::move_iterator<_IteratorL>'
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1760 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:1047:57: note:   'const Puzzle' is not derived from 'const std::move_iterator<_IteratorL>'
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1045:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1045 |     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1045:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:1047:57: note:   'const Puzzle' is not derived from 'const std::pair<_T1, _T2>'
 1047 |              || (!(__y.first < __x.first) && __x.second < __y.second); }
      |                                              ~~~~~~~~~~~^~~~~~~~~~~~