Submission #645313

#TimeUsernameProblemLanguageResultExecution timeMemory
645313Hacv16Zoo (COCI19_zoo)C++17
0 / 110
1 ms1236 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAX = 1015; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int dx[] = {0, 0, 1, -1}; const int dy[] = {1, -1, 0, 0}; #define pb push_back #define sz(x) (int) x.size() #define fr first #define sc second #define mp make_pair #define all(x) x.begin(), x.end() #define dbg(x) cerr << #x << ": " << "[ " << x << " ]\n" ll n, m, ans; char t[MAX][MAX]; void dfs(ll x, ll y){ char c = t[x][y]; t[x][y] = '*'; for(int i = 0; i < 4; i++){ ll nx = x + dx[i], ny = y + dy[i]; if(t[nx][ny] == c) dfs(nx, ny); } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; memset(t, '*', sizeof(t)); for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin >> t[i][j]; } } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(t[i][j] != '*') dfs(i, j), ans++; } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...