Language: C++

#include<bits/stdc++.h>
#define MST(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(int i = a ; i < b ; ++i)
#define per(i,a,b) for(int i = a ; i > b ; --i)
#define ALL(v) v.begin(),v.end()
#define ft first
#define sd second
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
template<class T> void show(T *x,int len,int s = 0) {for(int i = s ; i < s+len-1 ; ++i) cout << x[i] << ' ';cout << x[s+len-1] << endl;}
void debug() {cout << endl;}
template <typename T, typename... Args> void debug(T x,Args... args) {cout << x << ' ';debug(args...);}

namespace fast_IO{
    const int maxbuff = 1<<17;
    char ibuff[maxbuff],obuff[maxbuff];
    inline char Getchar(){
        static char *p1=ibuff,*p2=ibuff;
        if(p1 == p2) {
            p1 = ibuff;
            p2 = ibuff+fread(ibuff,1,maxbuff,stdin);
            if(p1 == p2) return -1;
        }
        return *p1++;
    }

    int optr = 0;
    inline void Putchar(char c) {
        if(optr == maxbuff) {fwrite(obuff,1,optr,stdout);optr = 0;}
        obuff[optr++] = c;
    }

    inline void Flush() {
        fwrite(obuff,1,optr,stdout);
    }

    template<class T>
    inline int read(T &x) {
        x = 0;
        char c = Getchar();
        if(c == EOF) return -1;
        for( ; (c < '0' || c > '9') && c != EOF ; c = Getchar());
        if(c == EOF) return -1;
        for( ; c >= '0' && c <= '9' ; c = Getchar()) x = x*10+c-'0';
        return 0;
    }

    template<class T>
    inline void write(const T &x,int tag = 0) {
        if(!x) {
            if(!tag) Putchar(x+'0');
            return ;
        }
        write(x/10,1);
        Putchar(x%10+'0');
    }

    template<class T>
    inline void writeln(const T &x) {
        write(x);Putchar('\n');
    }

    template<class T>
    inline void writesp(const T &x) {
        write(x);Putchar(' ');
    }
}
template<class T>
inline void cmin(T &A,const T &B) {A = (A<B?A:B);}
template<class T>
inline void cmax(T &A,const T &B) {A = (A>B?A:B);}

const int N = 185+19,D = 17;
char f[N][N][N][D],g[N][N][N][D],sum[N][N],n,m,mp[N][N];

namespace solution{
    void init() {
        for(int i = 1 ; i <= n ; ++i)
            for(int j = 1 ; j <= m ; ++j)
                sum[i][j] = mp[i][j]+sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
    }

    bool same_color(int x1,int y1,int x2,int y2) {
        int num = sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];
        return !num || num == (x2-x1+1)*(y2-y1+1);
    }

    void calc0() {
        for(int i = 1 ; i <= n ; ++i)
            for(int j = i ; j <= n ; ++j)
                for(int k = 1 ; k <= m ; ++k) {
                    int l = k-1 , r = m+1;
                    for(int mid = l+r>>1 ; l < r-1 ; mid = l+r>>1)
                        if ( same_color(i,k,j,mid) )
                            l = mid;
                        else
                            r = mid;
                    f[i][j][k][0] = l;

                    //if(same_color(i,k,j,l)) {cout << "OK" << i << ' ' << j << ' ' << k << ' ' << l << endl;}
                    //else cerr << i << ' ' << j << ' ' << k << ' ' << l << endl;
                }
        for(int i = 1 ; i <= m ; ++i)
            for(int j = i ; j <= m ; ++j)
                for(int k = 1 ; k <= n ; ++k) {
                    int l = k-1 , r = n+1;
                    for(int mid = l+r>>1 ; l < r-1 ; mid = l+r>>1)
                        if ( same_color(k,i,mid,j) )
                            l = mid;
                        else
                            r = mid;
                    g[i][j][k][0] = l;

                    //if(same_color(k,i,l,j)) {cout << "OK" << i << ' ' << j << ' ' << k << ' ' << l << endl;}
                    //else cerr << i << ' ' << j << ' ' << k << ' ' << l << endl;
                }
    }

    void calc_row(int &val,int i,int j,int k,int w) {
        int l = k , r = m+1;
        for(int mid = l+r >> 1 ; l < r-1 ; mid = l+r>>1) {
            int p = g[k][mid][i][w-1];
            if(p >= j) {
                l = mid;
                continue;
            }
            p = g[k][mid][p+1][w-1];
            if(p >= j) {
                l = mid;
                continue;
            }
            r = mid;
        }
        val = max(val,l);
    }

    void calc_col(int &val,int i,int j,int k,int w) {
        int l = k , r = n+1;
        for(int mid = l+r >> 1 ; l < r-1 ; mid = l+r>>1) {
            int p = f[k][mid][i][w-1];
            if(p >= j) {
                l = mid;
                continue;
            }
            p = f[k][mid][p+1][w-1];
            if(p >= j) {
                l = mid;
                continue;
            }
            r = mid;
        }
        val = max(val,l);
    }

    void calc() {
        for(int w = 1 ; w < D ; ++w) {
            for(int i = 1 ; i <= n ; ++i)
                for(int j = i ; j <= n ; ++j)
                    for(int k = 1 ; k <= m ; ++k) {
                        int p = f[i][j][k][w - 1];
                        if (p == m) {
                            f[i][j][k][w] = m;

                            continue;
                        }
                        f[i][j][k][w] = f[i][j][p + 1][w-1];

                        calc_row(f[i][j][k][w], i, j, k, w);

                    }

            for(int i = 1 ; i <= m ; ++i)
                for(int j = 1 ; j <= m ; ++j)
                    for(int k = 1 ; k <= n ; ++k) {
                        int p = g[i][j][k][w - 1];
                        if (p == n) {
                            g[i][j][k][w] = n;

                            continue;
                        }
                        g[i][j][k][w] = g[i][j][p + 1][w-1];

                        calc_col(g[i][j][k][w], i, j, k, w);

                    }
        }
    }

    void show() {
        debug("f");
        for (int w = 0; w < D; ++w)
            for (int i = 1; i <= n; ++i)
                for (int j = i ; j <= n ; ++j)
                    for(int k = 1 ; k <= m ; ++k)
                        debug(i,j,k,w,f[i][j][k][w]);
        debug();
        debug('g');
        for (int w = 0; w < D; ++w)
            for (int i = 1; i <= m; ++i)
                for (int j = i ; j <= m ; ++j)
                    for(int k = 1 ; k <= n ; ++k)
                        debug(i,j,k,w,g[i][j][k][w]);
    }
}


int main() {
#ifdef LOCAL
    freopen("input","r",stdin);
	freopen("output","w",stdout);
#endif

    cin >> n >> m;

    for(int i = 1 ; i <= n ; ++i) {
        string s;
        cin >> s;
        for(int j = 0 ; j < m ; ++j)
            if(s[j] == '.')
                mp[i][j+1] = 0;
            else
                mp[i][j+1] = 1;
    }

    solution::init();
    solution::calc0();
    solution::calc();

    for(int i = 0 ; i < D ; ++i)
        if(f[1][n][1][i] == m)  {
            cout << i << endl;
            break;
        }
    //solution::show();
    return 0;
}


Compiler output:
a.cc: In function 'void solution::calc()':
a.cc:172:46: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'char'
  172 |                         calc_row(f[i][j][k][w], i, j, k, w);
      |                                  ~~~~~~~~~~~~^
a.cc:123:24: note:   initializing argument 1 of 'void solution::calc_row(int&, int, int, int, int)'
  123 |     void calc_row(int &val,int i,int j,int k,int w) {
      |                   ~~~~~^~~
a.cc:187:46: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'char'
  187 |                         calc_col(g[i][j][k][w], i, j, k, w);
      |                                  ~~~~~~~~~~~~^
a.cc:141:24: note:   initializing argument 1 of 'void solution::calc_col(int&, int, int, int, int)'
  141 |     void calc_col(int &val,int i,int j,int k,int w) {
      |                   ~~~~~^~~