제출 #329732

#제출 시각아이디문제언어결과실행 시간메모리
329732aris12345678Zoo (COCI19_zoo)C++14
0 / 110
1 ms748 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pi pair<int, int> #define fi first #define se second const int mxN = 1e4+5; const int mod = 1e9+7; const ll inf = 1e18; int n, m, di[4] = {1, -1, 0, 0}, dj[4] = {0, 0, 1, -1}; string s[mxN]; bool vis[mxN][mxN]; bool is(int i, int j, char c) { return i >= 0 && j >= 0 && i < n && j < m && s[i][j] != '*' && s[i][j] == c && !vis[i][j]; } void dfs(int i, int j, char c) { vis[i][j] = 1; for(int k = 0; k < 4; k++) { for(int l = 0; l < 4; l++) { if(is(di[k]+i, dj[l]+j, s[i][j])) dfs(di[k]+i, dj[l]+j, s[i][j]); } } } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 0; i < n; i++) cin >> s[i]; int ans = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { if(is(i, j, s[i][j])) { ++ans; dfs(i, j, s[i][j]); } } } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...