# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
899197 | Blagoj | Emacs (COCI20_emacs) | C++17 | 0 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |