Submission

Status:
PPPPPPPP

Score: 100

User: akuyga1

Problemset: Sirabyrinth 2

Language: cpp

Time: 0.000 second

Submitted On: 2024-11-29 17:00:33

#include<bits/stdc++.h>
using namespace std;
int main(){
    int H,W;
    cin>>H>>W;
    string lab[H];
    for(auto& i:lab)cin>>i;
    //for(auto i:lab)cout<<i<<endl;
    int x,y;
    for(int i=0;i<H;i++)for(int j=0;j<W;j++)if(lab[i][j]=='S'){x=j;y=i;break;}
    //cout<<x<<' '<<y;
    int c=0;
    queue<pair<int,int>> Q;
    //first is x second is y
    Q.push({x,y});
    while(!Q.empty()){
        x=Q.front().first; y=Q.front().second;
        if(lab[y][x]=='#')Q.pop();
        else{
            c++;
            lab[y][x]='#';
            if(x>0)Q.push({x-1,y});
            if(x<W-1)Q.push({x+1,y});
            if(y>0)Q.push({x,y-1});
            if(y<H-1)Q.push({x,y+1});
        }
    }
    cout<<c;
}