Submission #74293344


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

int main()
{
    cin.tie(0)->sync_with_stdio(0);

    int h, w;
    cin >> h >> w;
    vector<vector<char>> grid(h, vector<char>(w));
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> grid[i][j];
        }
    }
    int dx[] = {-1, +1, 0, 0};
    int dy[] = {0, 0, +1, -1};
    auto dfs = [&](auto &&self, int x, int y) -> void
    {
        grid[x][y] = '#';
        for (int i = 0; i < 4; i++)
        {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx >= 0 && nx < h && ny >= 0 && ny < w && grid[nx][ny] == '.')
            {
                self(self, nx, ny);
            }
        }
    };

    for (int i = 0; i < h; i++)
    {
        if (grid[i][0] == '.')
        {
            dfs(dfs, i, 0);
        }
        if (grid[i][w - 1] == '.')
        {
            dfs(dfs, i, w - 1);
        }
    }
    for (int j = 0; j < w; j++)
    {
        if (grid[0][j] == '.')
        {
            dfs(dfs, 0, j);
        }
        if (grid[h - 1][j] == '.')
        {
            dfs(dfs, h - 1, j);
        }
    }
    int ans = 0;
    for (int i = 1; i < h - 1; i++)
    {
        for (int j = 1; j < w - 1; j++)
        {
            if (grid[i][j] == '.')
            {
                ans++;
                dfs(dfs, i, j);
            }
        }
    }
    cout << ans;

    return 0;
}

Submission Info

Submission Time
Task C - Puddles
User RageLog
Language C++23 (GCC 15.2.0)
Score 300
Code Size 1497 Byte
Status AC
Exec Time 57 ms
Memory 51160 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
min.txt AC 2 ms 3592 KiB
random_01.txt AC 12 ms 4300 KiB
random_02.txt AC 5 ms 3880 KiB
random_03.txt AC 14 ms 4328 KiB
random_04.txt AC 8 ms 3864 KiB
random_05.txt AC 19 ms 4328 KiB
random_06.txt AC 3 ms 3620 KiB
random_07.txt AC 17 ms 4304 KiB
random_08.txt AC 2 ms 3752 KiB
random_09.txt AC 23 ms 5456 KiB
random_10.txt AC 19 ms 5328 KiB
random_11.txt AC 25 ms 5712 KiB
random_12.txt AC 2 ms 3720 KiB
random_13.txt AC 39 ms 22988 KiB
random_14.txt AC 4 ms 5016 KiB
random_15.txt AC 37 ms 23204 KiB
random_16.txt AC 16 ms 9896 KiB
random_17.txt AC 8 ms 4260 KiB
random_18.txt AC 57 ms 51160 KiB
random_19.txt AC 14 ms 4308 KiB
random_20.txt AC 29 ms 27596 KiB
random_21.txt AC 40 ms 27840 KiB
sample_01.txt AC 1 ms 3488 KiB
sample_02.txt AC 2 ms 3472 KiB