Submission #731422

#TimeUsernameProblemLanguageResultExecution timeMemory
731422vjudge1Emacs (COCI20_emacs)C++17
50 / 50
1 ms340 KiB
#include <iostream> #include <queue> #include <cstring> #define int long long using namespace std; int dx[4] = {0, 0, -1, 1}; int dy[4] = {-1, 1, 0, 0}; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; bool a[n][m]; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { char c; cin >> c; a[i][j] = (c == '.'); } } int ans = 0; bool vis[n][m]; memset(vis, false, sizeof(vis)); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (vis[i][j]) continue; if (a[i][j]) continue; queue<pair<int, int>> q; q.push(make_pair(i, j)); while (!q.empty()) { pair<int, int> p = q.front(); q.pop(); int x = p.first, y = p.second; if (vis[x][y]) continue; vis[x][y] = true; for (int k = 0; k < 4; ++k) { int nx = x + dx[k], ny = y + dy[k]; if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue; if (a[nx][ny]) continue; q.push(make_pair(nx, ny)); } } ++ans; } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...