Submission #704775

#TimeUsernameProblemLanguageResultExecution timeMemory
704775chenyanZoo (COCI19_zoo)C++17
0 / 110
0 ms340 KiB
#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'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...