제출 #345048

#제출 시각아이디문제언어결과실행 시간메모리
345048limabeansZoo (COCI19_zoo)C++17
0 / 110
1 ms492 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl const int maxn = 1010; int n, m; string g[maxn]; bool viz[maxn][maxn]; int cc = 0; void dfs(int x, int y, char c) { if (x<0 || y<0 || x>=n || y>=m) return; if (viz[x][y]) return; if (g[x][y]!=c) return; viz[x][y] = true; dfs(x-1,y,c); dfs(x+1,y,c); dfs(x,y-1,c); dfs(x,y+1,c); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; for (int i=0; i<n; i++) { cin>>g[i]; } for (int i=0; i<n; i++) { for (int j=0; j<m; j++) { if (g[i][j]=='*') { continue; } if (!viz[i][j]) { cc++; dfs(i,j,g[i][j]); } } } cout<<cc<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...