# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
899197 | Blagoj | Emacs (COCI20_emacs) | C++17 | 0 ms | 348 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;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
int n, m;
bool valid(int x, int y) {
return (x >= 0 && x < n && y >= 0 && y < m);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
vector<string> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
bool visited[n][m];
memset(visited, 0, sizeof(visited));
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (v[i][j] == '*' && !visited[i][j]) {
ans++;
queue<pair<int, int>> q;
q.push({i, j});
while (q.size()) {
auto cur = q.front();
q.pop();
for (int d = 0; d < 4; d++) {
int nx = cur.first + dx[d], ny = cur.second + dy[d];
if (valid(nx, ny) && !visited[nx][ny] && v[nx][ny] == '*') {
visited[nx][ny] = 1;
q.push({nx, ny});
}
}
}
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |