Submission #731422

# Submission time Handle Problem Language Result Execution time Memory
731422 2023-04-27T12:02:34 Z vjudge1 Emacs (COCI20_emacs) C++17
50 / 50
1 ms 340 KB
#include <iostream>
#include <queue>
#include <cstring>
#define int long long
using namespace std;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    bool a[n][m];
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            char c;
            cin >> c;
            a[i][j] = (c == '.');
        }
    }
    int ans = 0;
    bool vis[n][m];
    memset(vis, false, sizeof(vis));
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if (vis[i][j])
                continue;
            if (a[i][j])
                continue;
            queue<pair<int, int>> q;
            q.push(make_pair(i, j));
            while (!q.empty())
            {
                pair<int, int> p = q.front();
                q.pop();
                int x = p.first, y = p.second;
                if (vis[x][y])
                    continue;
                vis[x][y] = true;
                for (int k = 0; k < 4; ++k)
                {
                    int nx = x + dx[k], ny = y + dy[k];
                    if (nx < 0 || nx >= n || ny < 0 || ny >= m)
                        continue;
                    if (a[nx][ny])
                        continue;
                    q.push(make_pair(nx, ny));
                }
            }
            ++ans;
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 276 KB Output is correct
10 Correct 1 ms 212 KB Output is correct