Submission

Status:
PPPPPPPP

Score: 100

User: mydKN

Problemset: Sirabyrinth 2

Language: cpp

Time: 0.002 second

Submitted On: 2024-11-22 22:04:48

#include<bits/stdc++.h>

using namespace std;

#define maxn 110

typedef pair<int, int> pii;

int n, m;
string str[maxn];
int sx, sy;
queue<pii> q;
bool visited[maxn][maxn];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int cnt;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> m;
	for(int i=0;i<n;++i){
		cin >> str[i];
		for(int j=0;j<m;++j){
			if(str[i][j] == 'S'){
				sx = j;
				sy = i;
			}
		}
	}
	q.emplace(sx, sy);
	while(!q.empty()){
		int nowx = q.front().first;
		int nowy = q.front().second;
		q.pop();
		if(visited[nowy][nowx]) continue;
		visited[nowy][nowx] = 1;
		++cnt;
		for(int i=0;i<4;++i){
			int toy = nowy + dy[i];
			int tox = nowx + dx[i];
			if(str[toy][tox] == '.' && !visited[toy][tox]){
				q.emplace(tox, toy);
			}
		}
	}
	cout << cnt;
}