Submission #74291821


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 lll;
typedef unsigned __int128 ulll;

void solve() {
    int h,w;
    cin >> h >> w;
    vector<vector<char>> graph(h,vector<char>(w));
    vector<vector<int>> vis(h,vector<int>(w,0));
    for (int i = 0;i < h;i++) {
        for (int j = 0;j < w;j++) {
            cin >> graph[i][j];
            if (graph[i][j] == '#') {
                vis[i][j] = -1;
            }
        }
    }
    vector<int> di = {1,-1,0,0};
    vector<int> dj = {0,0,1,-1};
    queue<pair<int,int>> bfs;
    ll ans = 0;
    for (int i = 0;i < h;i++) {
        for (int j = 0;j < w;j++) {
            bool found = false;
            if (graph[i][j] == '.' && vis[i][j] == 0) {
                bfs.push({i,j});
                vis[i][j] = -1;
                found = true;
            }
            bool is = false;
            while(!bfs.empty()) {
                auto &[ii,jj] = bfs.front();
                bfs.pop();
                for (int i = 0;i < 4;i++) {
                    int cur_i = ii + di[i];
                    int cur_j = jj + dj[i];
                    if (cur_i < 0 || cur_i >= h || cur_j < 0 || cur_j >= w) {
                        if (!is) {
                            is = true;
                        }
                        continue;
                    }
                    if (vis[cur_i][cur_j] == -1) {
                        continue;
                    }
                    vis[cur_i][cur_j] = -1;
                    bfs.push({cur_i,cur_j});
                }
            }
            if (found && !is) {
                ans++;
            }
        }
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Submission Info

Submission Time
Task C - Puddles
User t154654
Language C++23 (GCC 15.2.0)
Score 300
Code Size 1863 Byte
Status AC
Exec Time 30 ms
Memory 8640 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 3588 KiB
random_01.txt AC 16 ms 8344 KiB
random_02.txt AC 5 ms 4924 KiB
random_03.txt AC 16 ms 8280 KiB
random_04.txt AC 8 ms 5892 KiB
random_05.txt AC 26 ms 8404 KiB
random_06.txt AC 2 ms 3708 KiB
random_07.txt AC 26 ms 8416 KiB
random_08.txt AC 2 ms 3832 KiB
random_09.txt AC 30 ms 8532 KiB
random_10.txt AC 22 ms 7300 KiB
random_11.txt AC 30 ms 8608 KiB
random_12.txt AC 1 ms 3528 KiB
random_13.txt AC 25 ms 8580 KiB
random_14.txt AC 3 ms 3924 KiB
random_15.txt AC 25 ms 8580 KiB
random_16.txt AC 8 ms 5168 KiB
random_17.txt AC 10 ms 8212 KiB
random_18.txt AC 16 ms 8640 KiB
random_19.txt AC 12 ms 8344 KiB
random_20.txt AC 13 ms 8280 KiB
random_21.txt AC 13 ms 8268 KiB
sample_01.txt AC 1 ms 3588 KiB
sample_02.txt AC 1 ms 3540 KiB