Language: C++

#include <map>
#include <queue>
#include <string>
#include <vector>
#include <iostream>
#include <functional>

using namespace std;

struct state
{
	vector<string> v;

	int dist1;
	int dist2;

	state(vector<string> v1, int d1, int d2) : v(v1), dist1(d1), dist2(d2) { }
};

bool operator<(const state& s1, const state& s2) { return s1.dist1 + s1.dist2 < s2.dist1 + s2.dist2; }
bool operator<(const state& s1, const state& s2) { return s1.dist1 + s1.dist2 < s2.dist1 + s2.dist2; }

int W, H; vector<string> start;

map<vector<string>, bool> M;

int getdistance(vector<string> v)
{
	int ret = 0;

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (v[i][j] == '.')
			{
				ret++;
			}
		}
	}

	return ret;
}

int main()
{
	while (true)
	{
		scanf("%d", &W);
		scanf("%d", &H);

		M.clear();

		if (W == 0 && H == 0) break;

		start = vector<string>(H);

		for (int i = 0; i < H; i++) cin >> start[i];

		priority_queue<state, vector<state>, greater<state> > que;

		que.push(state(start, 0, getdistance(start))); M[start] = true;

		while (!que.empty())
		{
			state s1 = que.top(); que.pop();

			if (s1.dist2 == 0)
			{
				printf("%d\n", s1.dist1); break;
			}

			for (int i = 1; i <= 10; i++)
			{
				for (int j = 0; j <= H - i; j++)
				{
					for (int k = 0; k <= W - i; k++)
					{
						vector<string> v2 = s1.v;

						bool flag = true;

						for (int l = j; l < j + i; l++)
						{
							for (int m = k; m < k + i; m++)
							{
								if (v2[i][j] == '*')
								{
									flag = true; break;
								}
								else
								{
									v2[i][j] = '+';
								}
							}

							if (flag) break;
						}

						if (!M[v2])
						{
							M[v2] = true;

							que.push(state(v2, s1.dist1 + 1, getdistance(v2)));
						}
					}
				}
			}
		}
	}

	return 0;
}

Compiler output:
a.cc:21:6: error: redefinition of 'bool operator<(const state&, const state&)'
   21 | bool operator<(const state& s1, const state& s2) { return s1.dist1 + s1.dist2 < s2.dist1 + s2.dist2; }
      |      ^~~~~~~~
a.cc:20:6: note: 'bool operator<(const state&, const state&)' previously defined here
   20 | bool operator<(const state& s1, const state& s2) { return s1.dist1 + s1.dist2 < s2.dist1 + s2.dist2; }
      |      ^~~~~~~~
In file included from /usr/include/c++/14/bits/stl_tree.h:65,
                 from /usr/include/c++/14/map:62,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_function.h: In instantiation of 'constexpr bool std::greater<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = state]':
/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<state*, std::vector<state> >; _Value = state; _Compare = std::greater<state>]'
  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<state*, vector<state> >; _Distance = long int; _Tp = state; _Compare = __gnu_cxx::__ops::_Iter_comp_val<greater<state> >]'
  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<state*, vector<state> >; _Compare = greater<state>]'
  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 = state; _Sequence = std::vector<state>; _Compare = std::greater<state>; value_type = state]'
  747 |         std::push_heap(c.begin(), c.end(), comp);
      |         ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:62:11:   required from here
   62 |                 que.push(state(start, 0, getdistance(start))); M[start] = true;
      |                 ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_function.h:395:20: error: no match for 'operator>' (operand types are 'const state' and 'const state')
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/bits/stl_tree.h:63:
/usr/include/c++/14/bits/stl_pair.h:1058:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator>(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1058 |     operator>(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1058:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const state' is not derived from 'const std::pair<_T1, _T2>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:462:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  462 |     operator>(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:462:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const state' is not derived from 'const std::reverse_iterator<_Iterator>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:507:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  507 |     operator>(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:507:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const state' is not derived from 'const std::reverse_iterator<_Iterator>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1714 |     operator>(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1714:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const state' is not derived from 'const std::move_iterator<_IteratorL>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1774 |     operator>(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1774:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:395:20: note:   'const state' is not derived from 'const std::move_iterator<_IteratorL>'
  395 |       { return __x > __y; }
      |                ~~~~^~~~~