Submission #930404

#TimeUsernameProblemLanguageResultExecution timeMemory
930404WhisperEmacs (COCI20_emacs)C++17
50 / 50
1 ms1628 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; using ll = long long; using str = string; const ll dx[4] = {-1, 0, 0, 1}; const ll dy[4] = {0, -1, 1, 0}; const ll dx1[8] = {-1, -1, 1, 1, 0, 0, -1, 1}; const ll dy1[8] = {-1, 1, -1, 1, -1, 1, 0, 0}; const ll N = 1e6 + 5; const ll inf = (1e9 + 5); const ll MOD = 1e9 + 7; char a[1001][1001]; bool visited[1001][1001]; ll n, m; ll cnt = 0; void DFS( ll i , ll j ){ visited[i][j] = true; for (int k = 0; k < 8; k++ ){ ll i1 = i + dx1[k]; ll j1 = j + dy1[k]; if ( !visited[i1][j1] && i1 >= 1 && i1 <= n && j1 >= 1 && j1 <= m && a[i1][j1] != '.'){ DFS(i1, j1); } } } int main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n ; i++ ){ for ( int j = 1 ; j <= m ; j++ ){ cin >> a[i][j]; } } memset(visited, false, sizeof(visited)); for (int i = 1; i <= n; i++ ){ for (int j = 1; j <= m ; j++ ){ if ( !visited[i][j] && a[i][j] == '*'){ ++cnt; DFS(i, j); } } } cout << cnt; }
#Verdict Execution timeMemoryGrader output
Fetching results...