Submission #1090751

#TimeUsernameProblemLanguageResultExecution timeMemory
1090751laureZoo (COCI19_zoo)C++14
0 / 110
0 ms348 KiB
#include<bits/stdc++.h> #define int long long using namespace std; char g[1005][1005]; bool vis[1005][1005]; int n,m; queue<pair<int,int>>q; pair<int,int>mv[4]={{0,1},{0,-1},{1,0},{-1,0}}; void bfs(int i,int j) { q.push({i,j}); while(!q.empty()) { int i1=q.front().first; int j1=q.front().second; q.pop(); vis[i1][j1]=1; for(int k=0;k<4;k++) { int i2=i1+mv[k].first; int j2=j1+mv[k].second; if(i2>=0&&i2<n&&j2>=0&&j2<m) { if(!vis[i2][j2]&&g[i2][j2]==g[i][j])q.push({i2,j2}); } } } } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; for(int i=0;i<n;i++) { for(int j=0;j<m;j++)cin>>g[i][j]; } int ans=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(!vis[i][j]) { if(g[i][j]!='*') { ans++; bfs(i,j); } } } } cout<<ans<<'\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...