From 88960532705f63ae34001912c993b0d319fae1bb Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 8 Jun 2026 22:12:04 +0900 Subject: [PATCH] =?UTF-8?q?2589=20:=20=EB=B3=B4=EB=AC=BC=EC=84=AC=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ2589/BOJ2589_V1.cpp | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/week3/BOJ2589/BOJ2589_V1.cpp diff --git a/src/week3/BOJ2589/BOJ2589_V1.cpp b/src/week3/BOJ2589/BOJ2589_V1.cpp new file mode 100644 index 0000000..b62c34b --- /dev/null +++ b/src/week3/BOJ2589/BOJ2589_V1.cpp @@ -0,0 +1,60 @@ +#include +using namespace std; +vector> inp_map; +vector> lands; +vector> visited; +int dy[4] = {-1, 0, 1, 0}; +int dx[4] = {0, 1, 0, -1}; +int L, W; + +int main() { + + cin >> L >> W; + + for (int i=0; i < L; i++) { + inp_map.push_back(vector()); + visited.push_back(vector()); + string temp; + cin >> temp; + for (int j=0; j < W; j++) { + if (temp[j] == 'W') + inp_map[i].push_back(0); + else { + inp_map[i].push_back(1); + lands.push_back(make_pair(i, j)); + } + + visited[i].push_back(0); + } + } + + int max_distance = -1; + for (pair land : lands) { + queue> q; + q.push(land); + int distance = 0; + visited[land.first][land.second] = 1; + while(!q.empty()) { + pair p = q.front(); + q.pop(); + + for (int i=0; i<4; i++) { + int ny = p.first + dy[i]; + int nx = p.second + dx[i]; + + if (ny >= 0 && nx >= 0 && ny < L && nx < W) { + if (inp_map[ny][nx] == 1 && !visited[ny][nx]) { + q.push(make_pair(ny, nx)); + visited[ny][nx] = visited[p.first][p.second] + 1; + max_distance = max(max_distance, visited[ny][nx]); + } + } + } + } + fill(visited.begin(), visited.end(), vector(W,0)); + } + + cout << max_distance-1 << '\n'; + + return 0; +} \ No newline at end of file