제출 #487601

#제출 시각아이디문제언어결과실행 시간메모리
487601KazamaHoangEmacs (COCI20_emacs)C++14
50 / 50
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 0, -1, 1}; const int dy[] = {1, -1, 0, 0}; int n, m; char a[105][105]; queue<pair<int, int>> qu; bool visited[105][105]; int result = 0; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; for (int i = 1; i <= n; ++ i) for (int j = 1; j <= m; ++ j) cin >> a[i][j]; for (int i = 1; i <= n; ++ i) for (int j = 1; j <= m; ++ j) if (visited[i][j] == false && a[i][j] == '*') { visited[i][j] = true; qu.push({i, j}); ++ result; while (!qu.empty()) { pair<int, int> cur = qu.front(); qu.pop(); for (int dir = 0; dir < 4; ++ dir) { pair<int, int> tmp = {cur.first + dx[dir], cur.second + dy[dir]}; if (tmp.first >= 1 && tmp.first <= n && tmp.second >= 1 && tmp.second <= m && !visited[tmp.first][tmp.second] && a[tmp.first][tmp.second] == '*') { visited[tmp.first][tmp.second] = true; qu.push(tmp); } } } } cout << result; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...