# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
640201 | iee | Emacs (COCI20_emacs) | C++17 | 1 ms | 596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
char c[N][N];
int vis[N][N], n, m;
const int nxt[4][2] = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
void dfs(int x, int y) {
if (vis[x][y] || c[x][y] != '*')
return;
vis[x][y] = 1;
for (int d = 0; d < 4; ++d) {
int dx = x + nxt[d][0], dy = y + nxt[d][1];
if (dx < 1 || dy < 1 || dx > n || dy > m) continue;
dfs(dx, dy);
}
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> c[i] + 1;
int tot = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (!vis[i][j] && c[i][j] == '*')
++tot, dfs(i, j);
cout << tot;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |