#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define N 2010
char c[N][N];
int boss[N*N];
int find(int x){
return boss[x]?boss[x]=find(boss[x]):x;
}
void Union(int u,int v){
u=find(u),v=find(v);
if(u==v)return;
boss[u]=v;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,i,j;
cin>>n>>m;
for(i=1;i<=n;i++)for(j=1;j<=m;j++)
cin>>c[i][j];
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(c[i][j]=='*')continue;
if(c[i][j+1]==c[i][j])Union(i*N+j,i*N+j+1);
if(c[i+1][j]==c[i][j])Union((i+1)*N+j,i*N+j);
}
}
int ans=0;
for(i=1;i<=n;i++)for(j=1;j<=m;j++)
if(c[i][j]!='*'&&boss[i*N+j]==0)ans++;
cout<<ans<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |