-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path210205_BOJ_2589.cpp
More file actions
74 lines (56 loc) · 1.14 KB
/
Copy path210205_BOJ_2589.cpp
File metadata and controls
74 lines (56 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int N, M;
vector<vector<char>> v;
int dir[4][2]{ {-1, 0}, {0, 1}, {1, 0}, {0, -1} };
int Max = 0;
void input() {
cin >> N >> M;
v.assign(N, vector<char>(M));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
cin >> v[i][j];
}
}
}
void bfs(int a, int b) {
queue<pair<pair<int, int>, int>> q;
vector<vector<bool>> visit(N, vector<bool>(M, false));
q.push( { {a, b}, 0 } );
visit[a][b] = true;
while (!q.empty()) {
int x = q.front().first.first;
int y = q.front().first.second;
int time = q.front().second;
q.pop();
if (Max < time)
Max = time;
for (int i = 0; i < 4; ++i) {
int n_x = x + dir[i][0];
int n_y = y + dir[i][1];
if (!(n_x >= 0 && n_x < N && n_y >= 0 && n_y < M))
continue;
if (v[n_x][n_y] == 'W' || visit[n_x][n_y])
continue;
q.push({ {n_x, n_y}, time + 1 });
visit[n_x][n_y] = true;
}
}
}
void findAnswer() {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
if (v[i][j] == 'L') {
bfs(i, j);
}
}
}
cout << Max << "\n";
}
int main() {
input();
findAnswer();
return 0;
}