Submission #74283679


Source Code Expand

/*
Author:
    interstellar
site:
    AtGuesses.com
*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define ll long long
#define umap unordered_map
#define uset unordered_set
constexpr int inf = (int)1e9 + 5;
constexpr ll  llinf = (ll)1e18 + 5;
// constexpr int mod = ((int)1e9+7);
constexpr int mod = 998244353;

using namespace std;
#define vll vector<ll>
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vvi vector<vi>
#define vvll vector<vll>

void test_case(){
    int h, w;
    cin >> h >> w;

    vector<string> A(h);
    for (auto &p : A)cin >> p;
    vector<vi> vis(h, vi(w));
    int cc = 1;
    auto bfs = [&](int i, int j){
        queue<pair<int, int>> q;
        q.push({i, j});
        vector<pair<int, int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
        while (!q.empty()){
            auto &[r, c] = q.front();
            q.pop();
            if (vis[r][c])continue;
            vis[r][c] = cc;
            for (auto &[dr, dc] : dir){
                if (r + dr >= h || c + dc >= w || r + dr < 0 || c + dc < 0 || A[r + dr][c + dc] == '#')continue;
                q.push({r + dr, c + dc});
            }
        }
    };

    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (vis[i][j] || A[i][j] == '#')continue;
            bfs(i, j);
            cc++;
        }
    }
    set<int> s;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (i == 0 || i == h - 1 || j == 0 || j == w- 1){
                if (A[i][j] == '.')s.insert(vis[i][j]);
            }
        }
    }
    cout << cc - int(s.size()) - 1;
}

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

    test_case();

    return 0;
}
/*
*/

Submission Info

Submission Time
Task C - Puddles
User Interstellar001
Language C++23 (GCC 15.2.0)
Score 300
Code Size 2098 Byte
Status AC
Exec Time 38 ms
Memory 8760 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 3456 KiB
random_01.txt AC 15 ms 8760 KiB
random_02.txt AC 5 ms 5116 KiB
random_03.txt AC 15 ms 8760 KiB
random_04.txt AC 8 ms 6140 KiB
random_05.txt AC 25 ms 8608 KiB
random_06.txt AC 2 ms 3580 KiB
random_07.txt AC 25 ms 8608 KiB
random_08.txt AC 2 ms 3744 KiB
random_09.txt AC 37 ms 8604 KiB
random_10.txt AC 26 ms 7164 KiB
random_11.txt AC 38 ms 8576 KiB
random_12.txt AC 1 ms 3720 KiB
random_13.txt AC 34 ms 8712 KiB
random_14.txt AC 3 ms 3840 KiB
random_15.txt AC 35 ms 8608 KiB
random_16.txt AC 11 ms 5152 KiB
random_17.txt AC 6 ms 8404 KiB
random_18.txt AC 26 ms 8576 KiB
random_19.txt AC 24 ms 8668 KiB
random_20.txt AC 12 ms 8400 KiB
random_21.txt AC 12 ms 8480 KiB
sample_01.txt AC 1 ms 3488 KiB
sample_02.txt AC 1 ms 3640 KiB