Submission #74278467


Source Code Expand

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    for (int i = 0; i < h; i++) cin >> g[i];

    int ans = 0;
    vector<int> dx = {-1, 0, 1,  0};
    vector<int> dy = { 0, 1, 0, -1};
    vector<vector<bool>> f(h, vector<bool>(w, false));
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) if (g[i][j] == '.' && !f[i][j]) {
        int x1 = i, x2 = i, y1 = j, y2 = j;
        queue<pair<int, int>> q;
        q.push({i, j}), f[i][j] = true;
        while (!q.empty()) {
            auto [x, y] = q.front(); q.pop();
            for (int i = 0; i < 4; i++) {
                int u = x + dx[i], v = y + dy[i];
                if (u < 0 || u >= h || v < 0 || v >= w || g[u][v] == '#' || f[u][v]) continue;
                q.push({u, v}), f[u][v] = true;
                x1 = min(x1, u), x2 = max(x2, u);
                y1 = min(y1, v), y2 = max(y2, v);
            }
        }
        if (x1 == 0 || x2 == h - 1 || y1 == 0 || y2 == w - 1) continue;
        ans++;
    }
    cout << ans << '\n';
    return 0;
}

Submission Info

Submission Time
Task C - Puddles
User liangsheng
Language C++23 (GCC 15.2.0)
Score 300
Code Size 1186 Byte
Status AC
Exec Time 27 ms
Memory 4904 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 1 ms 3592 KiB
random_01.txt AC 11 ms 4788 KiB
random_02.txt AC 4 ms 3948 KiB
random_03.txt AC 10 ms 4864 KiB
random_04.txt AC 6 ms 4232 KiB
random_05.txt AC 19 ms 4904 KiB
random_06.txt AC 1 ms 3696 KiB
random_07.txt AC 19 ms 4844 KiB
random_08.txt AC 2 ms 3692 KiB
random_09.txt AC 27 ms 4872 KiB
random_10.txt AC 20 ms 4592 KiB
random_11.txt AC 27 ms 4880 KiB
random_12.txt AC 1 ms 3448 KiB
random_13.txt AC 22 ms 4736 KiB
random_14.txt AC 2 ms 3692 KiB
random_15.txt AC 22 ms 4704 KiB
random_16.txt AC 8 ms 4040 KiB
random_17.txt AC 2 ms 4872 KiB
random_18.txt AC 16 ms 4844 KiB
random_19.txt AC 15 ms 4844 KiB
random_20.txt AC 10 ms 4844 KiB
random_21.txt AC 10 ms 4732 KiB
sample_01.txt AC 1 ms 3592 KiB
sample_02.txt AC 1 ms 3624 KiB