Submission #899197

#TimeUsernameProblemLanguageResultExecution timeMemory
899197BlagojEmacs (COCI20_emacs)C++17
50 / 50
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define all(x) (x).begin(), (x).end() const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1}; int n, m; bool valid(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; vector<string> v(n); for (int i = 0; i < n; i++) cin >> v[i]; bool visited[n][m]; memset(visited, 0, sizeof(visited)); int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (v[i][j] == '*' && !visited[i][j]) { ans++; queue<pair<int, int>> q; q.push({i, j}); while (q.size()) { auto cur = q.front(); q.pop(); for (int d = 0; d < 4; d++) { int nx = cur.first + dx[d], ny = cur.second + dy[d]; if (valid(nx, ny) && !visited[nx][ny] && v[nx][ny] == '*') { visited[nx][ny] = 1; q.push({nx, ny}); } } } } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...