제출 #445126

#제출 시각아이디문제언어결과실행 시간메모리
445126Wasif_JamilZoo (COCI19_zoo)C++14
0 / 110
5 ms8140 KiB
// "Say:He is the Most Merciful,We have believed in him and upon him we have relied" [67:29] #include<bits/stdc++.h> using namespace std; vector<vector<int>>v(1001, vector<int>(1001)), vis(1001, vector<int>(1001)); int n, m; vector<pair<int,int>> dx = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; void dfs(int i, int j, int color){ //cout << i << " " << j << " " << color << "\n"; if(i < 1 or i > n or j < 1 or j > m){ return; } if(vis[i][j]){ return; } if(v[i][j] != color){ return; } vis[i][j] = 1; for(pair<int,int> u : dx){ dfs(i+u.first, j+u.second, color); } } int main(){ cin >> n >> m; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ char x; cin >> x; if(x == 'T'){ v[i][j] = 1; } if(x == 'B'){ v[i][j] = 2; } } } int ans = 0; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ if(vis[i][j] == 0 and v[i][j]){ ans++; dfs(i, j, v[i][j]); } } } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...