Language: C++

#include<cmath>
#include<ctime>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include <cstdio>
using namespace std;
const int N = 186;
char f[17][N][N][N];
int n, m ;
char a[N][N];
int sum[N][N];
int main(){
    scanf("%d %d", &n, &m);
    for (int i  = 1; i <= n ;  i++)
        for (int j = 1 ; j <= m ; j ++) {
            scanf(" %c", &a[i][j]);
            if (a[i][j] == '#')
                sum[i][j] = 1;
            sum[i][j] += sum[i - 1][j];
        }
    for (int cnt = 0; cnt < 17; cnt ++) {
        for (int i = m; i; i--)
            for (int hr = 1; hr <= n; hr++) {
                int mid = hr;
                for (int hl = hr; hl; hl--) {
                    if (cnt) {
                        while (mid - 1 > hl && min(f[cnt - 1][i][mid][hr], f[cnt - 1][i][hl][mid - 1]) <=
                                               min(f[cnt - 1][i][mid - 1][hr], f[cnt - 1][i][hl][mid - 2]))
                            mid--;
                        if (mid != hl)
                            f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr],
                                                    min(f[cnt - 1][i][mid][hr], f[cnt - 1][i][hl][mid - 1]));

                        if (f[cnt - 1][i][hl][hr] + i <= m)
                            f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], f[cnt - 1][i][hl][hr] +
                                                                       f[cnt - 1][i + f[cnt - 1][i][hl][hr]][hl][hr]);
                        else
                            f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], f[cnt - 1][i][hl][hr]);
                        f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], f[cnt - 1][i][hl][hr]);
                    } else {
                        if ((sum[hr][i] - sum[hl - 1][i]) % (hr - hl + 1) == 0) {
                            if (i == m)
                                f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], 1);
                            else {
                                if ((sum[hr][i] - sum[hl - 1][i]) == (sum[hr][i + 1] - sum[hl - 1][i + 1]))
                                    f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], f[cnt][i + 1][hl][hr] + 1);
                                else
                                    f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], 1);
                            }
                        }
                    }
                }
            }
        if (f[cnt][1][1][n] == m) {
            printf("%d\n", cnt);
            return 0;
        }
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:52: error: no matching function for call to 'max(char&, int)'
   38 |                             f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], f[cnt - 1][i][hl][hr] +
      |                                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   39 |                                                                        f[cnt - 1][i + f[cnt - 1][i][hl][hr]][hl][hr]);
      |                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:38:52: note:   deduced conflicting types for parameter 'const _Tp' ('char' and 'int')
   38 |                             f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], f[cnt - 1][i][hl][hr] +
      |                                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   39 |                                                                        f[cnt - 1][i + f[cnt - 1][i][hl][hr]][hl][hr]);
      |                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:38:52: note:   mismatched types 'std::initializer_list<_Tp>' and 'char'
   38 |                             f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], f[cnt - 1][i][hl][hr] +
      |                                                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   39 |                                                                        f[cnt - 1][i + f[cnt - 1][i][hl][hr]][hl][hr]);
      |                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:46:56: error: no matching function for call to 'max(char&, int)'
   46 |                                 f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], 1);
      |                                                     ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:46:56: note:   deduced conflicting types for parameter 'const _Tp' ('char' and 'int')
   46 |                                 f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], 1);
      |                                                     ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:46:56: note:   mismatched types 'std::initializer_list<_Tp>' and 'char'
   46 |                                 f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], 1);
      |                                                     ~~~^~~~~~~~~~~~~~~~~~~~~~
a.cc:49:60: error: no matching function for call to 'max(char&, int)'
   49 |                                     f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], f[cnt][i + 1][hl][hr] + 1);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:49:60: note:   deduced conflicting types for parameter 'const _Tp' ('char' and 'int')
   49 |                                     f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], f[cnt][i + 1][hl][hr] + 1);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:49:60: note:   mismatched types 'std::initializer_list<_Tp>' and 'char'
   49 |                                     f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], f[cnt][i + 1][hl][hr] + 1);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:51:60: error: no matching function for call to 'max(char&, int)'
   51 |                                     f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], 1);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:51:60: note:   deduced conflicting types for parameter 'const _Tp' ('char' and 'int')
   51 |                                     f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], 1);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:51:60: note:   mismatched types 'std::initializer_list<_Tp>' and 'char'
   51 |                                     f[cnt][i][hl][hr] = max(f[cnt][i][hl][hr], 1);
      |                                                         ~~~^~~~~~~~~~~~~~~~~~~~~~