# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
487601 | KazamaHoang | Emacs (COCI20_emacs) | C++14 | 1 ms | 336 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 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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |