Submission
Status:
PPPPPPPP
Score: 100
User: Nathlol2
Problemset: Sirabyrinth 2
Language: cpp
Time: 0.003 second
Submitted On: 2024-11-26 18:37:51
#include <bits/stdc++.h>
using namespace std;
int mx[4] = {0,0,-1,1};
int my[4] = {1,-1,0,0};
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int e, w, n, m;
char a[105][105];
vector<vector<bool>> v(105,vector<bool>(105, false));
cin >> n >> m;
for(int i = 0;i<n;i++){
for(int j = 0;j<m;j++){
cin >> a[i][j];
if(a[i][j] == 'S'){
e = i;
w = j;
}
}
}
//BFS
int c = 0;
queue<pair<int, int>> q;
q.push({e, w});
while(!q.empty()){
int x = q.front().first;
int y = q.front().second;
q.pop();
if(!v[x][y]){
v[x][y] = true;
}else continue;
c++;
for(int i = 0;i<4;i++){
int nx = x + mx[i];
int ny = y + my[i];
if(nx < 0 || ny < 0 || nx >= n || ny >= m){
continue;
}
if(a[nx][ny] == '.' && !v[nx][ny]){
q.push({nx, ny});
}
}
}
cout << c;
}