Submission #640201

#TimeUsernameProblemLanguageResultExecution timeMemory
640201ieeEmacs (COCI20_emacs)C++17
50 / 50
1 ms596 KiB
#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)

emacs.cpp: In function 'int main()':
emacs.cpp:20:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |     cin >> c[i] + 1;
      |            ~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...