https://www.luogu.com.cn/record/33907924
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#define maxn 1501
#define getnum(x,y) ((x-1)*m+y+1)
using namespace std;
vector<int> to[maxn];
char s[maxn][maxn];
int n,m;
void insize(){
int i,j;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
cin>>s[i];
for(i=1;i<=n;i++)
for(j=0;j<m;j++)
if(s[i][j]=='*'){
int tmp=getnum(i,j);
if(i!=0) if(s[i-1][j]=='*'){
to[tmp].push_back(getnum(i-1,j));
to[getnum(i-1,j)].push_back(tmp);
}
if(j!=0) if(s[i][j-1]=='*'){
to[tmp].push_back(getnum(i,j-1));
to[getnum(i,j-1)].push_back(tmp);
}
if(i!=0&&j!=0) if(s[i-1][j-1]=='*'){
to[tmp].push_back(getnum(i-1,j-1));
to[getnum(i-1,j-1)].push_back(tmp);
}
if(i!=0&&j!=n-1) if(s[i-1][j+1]=='*'){
to[tmp].push_back(getnum(i-1,j+1));
to[getnum(i-1,j+1)].push_back(tmp);
}
}
return;
}
int f[maxn*maxn],t[100039];
int stack[1000039],top;
int dfs(int x){
top=2;
stack[1]=x;
int tmp,i,sum=1;
f[x]=1;
while(top>1){
top--; tmp=stack[top];
for(i=0;i<to[tmp].size();i++){
if(f[to[tmp][i]]==1) continue;
f[to[tmp][i]]=1;
sum++;
stack[top]=to[tmp][i];
top++;
}
}
return sum;
}
void getans(){
int i,j;
memset(f,0,sizeof(f));
for(i=1;i<=n;i++)
for(j=0;j<m;j++){
int tmp=getnum(i,j);
if(s[i][j]!='*'||f[tmp]!=0) continue;
t[dfs(tmp)]++;
}
int sum,maxx;
sum=0; maxx=-1;
for(i=1;i<=10000;i++){
if(t[i]!=0) sum++;
if(t[i]*i>maxx) maxx=t[i]*i;
}
printf("%d %d",sum,maxx);
return;
}
int main(){
//freopen("star.in","r",stdin);
//freopen("star.out","w",stdout);
insize();
getans();
return 0;
}