# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
640201 |
2022-09-14T00:28:55 Z |
iee |
Emacs (COCI20_emacs) |
C++17 |
|
1 ms |
596 KB |
#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
emacs.cpp: In function 'int main()':
emacs.cpp:20:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | cin >> c[i] + 1;
| ~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
452 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
576 KB |
Output is correct |