From 4a0c39c15e5e526aac8300fdd9ee667024bbb331 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 6 Jul 2026 15:53:23 +0900 Subject: [PATCH] =?UTF-8?q?14497=20:=20=EC=A3=BC=EB=82=9C=EC=9D=98=20?= =?UTF-8?q?=EB=82=9C(=E9=9B=A3)=20resolve/2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ14497/BOJ14497_V3.cpp | 58 ++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/week3/BOJ14497/BOJ14497_V3.cpp diff --git a/src/week3/BOJ14497/BOJ14497_V3.cpp b/src/week3/BOJ14497/BOJ14497_V3.cpp new file mode 100644 index 0000000..ca09e9e --- /dev/null +++ b/src/week3/BOJ14497/BOJ14497_V3.cpp @@ -0,0 +1,58 @@ +#include +using namespace std; +int N,M; +int jy, jx, ty, tx; +queue> q; +char inp[301][301]; +int visited[301][301]; +int dy[4] = {-1, 0, 1, 0}; +int dx[4] = {0, 1, 0, -1}; +int main() { + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + cin >> N >> M; + cin >> jy >> jx >> ty >> tx; + jy--; jx--; ty--; tx--; + for (int i = 0; i < N; i++) { + string s; + cin >> s; + for (int j=0; j> next_q; + while(!q.empty()) { + int qsize = q.size(); + pair curr = q.front(); + q.pop(); + + if (curr.first == ty && curr.second == tx) { + cout << cnt << '\n'; + return 0; + } + for (int i=0; i<4; i++) { + int ny = curr.first + dy[i]; + int nx = curr.second + dx[i]; + if (ny < 0 || ny >= N || nx < 0 || nx >= M || visited[ny][nx]) continue; + if (inp[ny][nx] != '0') { + next_q.push({ny, nx}); + } else { + q.push({ny, nx}); + } + visited[ny][nx] = 1; + } + } + q = next_q; + cnt++; + } + + + + return 0; +} \ No newline at end of file