Submission #1304141

#TimeUsernameProblemLanguageResultExecution timeMemory
1304141nathlol2Emacs (COCI20_emacs)C++20
50 / 50
1 ms576 KiB
#include <bits/stdc++.h> using namespace std; const int N = 105; string tb[N]; int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0}; int n, m, ans, vs[N][N]; void dfs(int x, int y){ for(int i = 0;i<4;i++){ int nx = x + dx[i], ny = y + dy[i]; if(nx >= 1 && nx <= n && ny >= 1 && ny <= m && !vs[nx][ny] && tb[nx][ny] == '*'){ vs[nx][ny] = 1; dfs(nx, ny); } } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i = 1;i<=n;i++) cin >> tb[i], tb[i] = " " + tb[i]; for(int i = 1;i<=n;i++){ for(int j = 1;j<=m;j++){ if(!vs[i][j] && tb[i][j] == '*'){ vs[i][j] = 1; ++ans; dfs(i, j); } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...