Language: C++

#include<bits/stdc++.h>
using namespace std;
#define nn 190
char _map[nn][nn];
int n,m;int cnt[nn][nn][2];

int ask(int x1,int y1,int x2,int y2,int t)
{
	x1--,y1--;
	return cnt[x2][y2][t]+cnt[x1][y1][t]-cnt[x1][y2][t]-cnt[x2][y1][t];
}
int ask(int x1,int y1,int x2,int y2)
{
	if(x1<1 or y1<1 or x2>n or y2>m) return 0;
	return !ask(x1,y1,x2,y2,0) or !ask(x1,y1,x2,y2,1); 
}

int to[2][nn][nn][nn][2];//where, 1=|

void chkmax(int &x,int y)
{
	x=max(x,y);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",_map[i]+1);
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
		if(_map[i][j]=='#') cnt[i][j][1]=1;
		else cnt[i][j][0]=1;
	
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
		for(int k=0;k<2;k++) cnt[i][j][k]+=cnt[i-1][j][k]+cnt[i][j-1][k]-cnt[i-1][j-1][k];
	
	int now=0;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
		int lst=m;
		for(int k=1;i+k-1<=n;k++)
		{
			while(lst>0 and !ask(i,j,i+k-1,j+lst-1)) lst--;
			to[now][i][j][k][1]=lst;
		}
		
		lst=n;
		for(int k=1;j+k-1<=m;k++)
		{
			while(lst>0 and !ask(i,j,i+lst-1,j+k-1)) lst--;
			to[now][i][j][k][0]=lst;
		}
	}
	int ans=0;
	if(to[now][1][1][n][1]>=m or to[now][1][1][m][0]>=n);else  
	while(ans<10000)
	{
		for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
		{
			for(int k=1;i+k-1<=n;k++)
			{
				int x=to[now][i][j][k][1]+j;int len=to[now][i][x][k][1]+x-1-j+1;
				chkmax(len,to[now][i][j][k][1]);
				chkmax(to[now^1][i][j][k][1],len);
				if(len>0 and len<=m) chkmax(to[now^1][i][j][len][0],k);
			}
			
			for(int k=1;j+k-1<=m;k++)
			{
				int x=to[now][i][j][k][0]+i;int len=to[now][x][j][k][0]+x-1-i+1;
				chkmax(len,to[now][i][j][k][0]);
				chkmax(to[now^1][i][j][k][0],len);
				if(len>0 and len<=n) chkmax(to[now^1][i][j][len][1],k);
			}
		
		}
		
		
		now^=1;
		int tmp=2;
		while(tmp--)
		{
			
			for(int k=n;k>=1;k--)
			for(int i=1;i+k-1<=n;i++) for(int j=1;j<=m;j++)
			{
				chkmax(to[now][i][j][k][1],to[now][i][j][k+1][1]),
		//		chkmax(to[now][i][j][k][1],to[now][i-1][j][k+1][1]),
		//		chkmax(to[now][i][j][k][1],to[now][i][j-1][k+1][1]);
				
				int len=to[now][i][j][k][1];
				chkmax(to[now][i][j][len][0],k);
			}
				
			
			for(int k=m;k>=1;k--)
			for(int i=1;i<=n;i++) for(int j=1;j+k-1<=m;j++)
			{
				chkmax(to[now][i][j][k][0],to[now][i][j][k+1][0]),
		//		chkmax(to[now][i][j][k][0],to[now][i-1][j][k+1][0]),
		//		chkmax(to[now][i][j][k][0],to[now][i][j-1][k+1][0]);
				
				int len=to[now][i][j][k][0];
				chkmax(to[now][i][j][len][1],k);
			}
			
		}	
		
		ans++;
		if(to[now][1][1][n][1]>=m or to[now][1][1][m][0]>=n) break;
		
	}
	printf("%d\n",ans);
	
	return 0;
} 

Compiler output:
a.cc: In function 'int main()':
a.cc:90:33: error: expected primary-expression before 'int'
   90 |                                 int len=to[now][i][j][k][1];
      |                                 ^~~
a.cc:91:54: error: 'len' was not declared in this scope
   91 |                                 chkmax(to[now][i][j][len][0],k);
      |                                                      ^~~
a.cc:102:33: error: expected primary-expression before 'int'
  102 |                                 int len=to[now][i][j][k][0];
      |                                 ^~~
a.cc:103:54: error: 'len' was not declared in this scope
  103 |                                 chkmax(to[now][i][j][len][1],k);
      |                                                      ^~~