Submission #74301033


Source Code Expand

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int dx[]={-1,1,0,0};const int dy[]={0,0,-1,1};
int h,w;vector<vector<char>>g;vector<vector<bool>>v;
void bfs(int x,int y){
    queue<pair<int,int>>q;q.push({x,y});v[x][y]=1;
    while(!q.empty()){
        auto [cx,cy]=q.front();q.pop();
        for(int d=0;d<4;++d){
            int nx=cx+dx[d],ny=cy+dy[d];
            if(nx>=0&&nx<h&&ny>=0&&ny<w&&!v[nx][ny]&&g[nx][ny]=='.'){
                v[nx][ny]=1;q.push({nx,ny});
            }
        }
    }
}
int main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);
    cin>>h>>w;g.resize(h,vector<char>(w));v.resize(h,vector<bool>(w,0));
    for(int i=0;i<h;++i)for(int j=0;j<w;++j)cin>>g[i][j];
    for(int j=0;j<w;++j){if(g[0][j]=='.'&&!v[0][j])bfs(0,j);if(g[h-1][j]=='.'&&!v[h-1][j])bfs(h-1,j);}
    for(int i=1;i<h-1;++i){if(g[i][0]=='.'&&!v[i][0])bfs(i,0);if(g[i][w-1]=='.'&&!v[i][w-1])bfs(i,w-1);}
    int a=0;
    for(int i=1;i<h-1;++i)for(int j=1;j<w-1;++j)if(g[i][j]=='.'&&!v[i][j]){a++;bfs(i,j);}
    cout<<a<<endl;return 0;
}

Submission Info

Submission Time
Task C - Puddles
User liminghan
Language C++ IOI-Style(GNU++20) (GCC 14.2.0)
Score 300
Code Size 1097 Byte
Status AC
Exec Time 38 ms
Memory 2984 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 0 ms 1704 KiB
random_01.txt AC 16 ms 2984 KiB
random_02.txt AC 5 ms 2088 KiB
random_03.txt AC 16 ms 2984 KiB
random_04.txt AC 8 ms 2344 KiB
random_05.txt AC 26 ms 2984 KiB
random_06.txt AC 1 ms 1704 KiB
random_07.txt AC 26 ms 2984 KiB
random_08.txt AC 1 ms 1832 KiB
random_09.txt AC 38 ms 2984 KiB
random_10.txt AC 28 ms 2600 KiB
random_11.txt AC 38 ms 2984 KiB
random_12.txt AC 1 ms 1704 KiB
random_13.txt AC 33 ms 2984 KiB
random_14.txt AC 3 ms 1832 KiB
random_15.txt AC 33 ms 2984 KiB
random_16.txt AC 10 ms 2088 KiB
random_17.txt AC 7 ms 2856 KiB
random_18.txt AC 19 ms 2984 KiB
random_19.txt AC 24 ms 2984 KiB
random_20.txt AC 14 ms 2984 KiB
random_21.txt AC 14 ms 2984 KiB
sample_01.txt AC 0 ms 1704 KiB
sample_02.txt AC 0 ms 1704 KiB