Submission #74304164


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
bool is_boun;
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
void dfs(vector<string>&grid,int H,int W,int r,int c,vector<vector<bool>>&visited){
    visited[r][c]=true;
    if(r==0||r==H-1||c==0||c==W-1){
        is_boun=true;
    }
    for(int i=0;i<4;i++){
        int xr=r+dx[i];
        int yc=c+dy[i];
        if(xr>=0&&xr<H&&yc>=0&&yc<W){
            if (grid[xr][yc] == '.' && !visited[xr][yc]) {
                dfs(grid,H,W,xr, yc,visited);
            }
        }
    }
}
int main(){
    int H,W;
    cin>>H>>W;
    vector<string>grid(H);
    for(int i=0;i<H;i++){
        cin>>grid[i];
    }
    vector<vector<bool>>visited(H,vector<bool>(W,false));
    
    int cnt=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(grid[i][j]=='.'&&!visited[i][j]){
                is_boun=false;
                dfs(grid,H,W,i,j,visited);
                if(!is_boun){
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;
}

Submission Info

Submission Time
Task C - Puddles
User VICKEY_KUMAR_123
Language C++23 (GCC 15.2.0)
Score 300
Code Size 1069 Byte
Status AC
Exec Time 66 ms
Memory 99400 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 3540 KiB
random_01.txt AC 17 ms 5648 KiB
random_02.txt AC 6 ms 3788 KiB
random_03.txt AC 17 ms 5648 KiB
random_04.txt AC 9 ms 4436 KiB
random_05.txt AC 24 ms 5724 KiB
random_06.txt AC 1 ms 3656 KiB
random_07.txt AC 24 ms 5724 KiB
random_08.txt AC 2 ms 3672 KiB
random_09.txt AC 32 ms 8220 KiB
random_10.txt AC 24 ms 7076 KiB
random_11.txt AC 32 ms 7764 KiB
random_12.txt AC 1 ms 3652 KiB
random_13.txt AC 47 ms 43684 KiB
random_14.txt AC 4 ms 6228 KiB
random_15.txt AC 46 ms 43520 KiB
random_16.txt AC 15 ms 15804 KiB
random_17.txt AC 12 ms 5772 KiB
random_18.txt AC 66 ms 99400 KiB
random_19.txt AC 15 ms 5680 KiB
random_20.txt AC 38 ms 52284 KiB
random_21.txt AC 38 ms 52240 KiB
sample_01.txt AC 1 ms 3404 KiB
sample_02.txt AC 1 ms 3592 KiB