From da656ce0f32b71f0059ed09b18e59f425ecaf690 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Sat, 27 Jun 2026 11:12:58 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ14497/BOJ14497_V2.cpp | 60 ++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/week3/BOJ14497/BOJ14497_V2.cpp diff --git a/src/week3/BOJ14497/BOJ14497_V2.cpp b/src/week3/BOJ14497/BOJ14497_V2.cpp new file mode 100644 index 0000000..4aa522b --- /dev/null +++ b/src/week3/BOJ14497/BOJ14497_V2.cpp @@ -0,0 +1,60 @@ +#include +using namespace std; +int visited[300][300]; +char inp[300][300]; +int dy[4] = {-1, 0, 1, 0}; +int dx[4] = {0, 1, 0, -1}; +int N,M,jx, jy, tx,ty; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> N >> M >> jy >> jx >> ty >> tx; + jy--;jx--;ty--;tx--; + for (int i=0; i> s; + for (int j=0; j> q; + q.push({jy, jx}); + visited[jy][jx] = 1; + + while(true) { + queue> next_q; + while(!q.empty()) { + pair p = q.front(); + q.pop(); + if (p.first == ty && p.second == tx) { + cout << cnt << '\n'; + return 0; + } + 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 >= N || nx >= M) continue; + if (visited[ny][nx]) continue; + if (inp[ny][nx] == '1') { + next_q.push({ny, nx}); + visited[ny][nx] = 1; + } else { + q.push({ny, nx}); + visited[ny][nx] = 1; + } + } + } + cnt++; + q = next_q; + } + + cout << cnt << '\n'; + + return 0; +} \ No newline at end of file