From 4d95eb680b2c51d6bf4cf082b54e1fc275c57456 Mon Sep 17 00:00:00 2001 From: DaeWook Kim Date: Wed, 10 Dec 2025 16:58:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=202025-12-10=20baekjoon=201697=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- daewook/2025-12-10_baekjoon_1697.cpp | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 daewook/2025-12-10_baekjoon_1697.cpp diff --git a/daewook/2025-12-10_baekjoon_1697.cpp b/daewook/2025-12-10_baekjoon_1697.cpp new file mode 100644 index 0000000..aedf858 --- /dev/null +++ b/daewook/2025-12-10_baekjoon_1697.cpp @@ -0,0 +1,41 @@ +#include +#include + +using namespace std; + +const int MAX = 100000; +int arr[MAX + 1]; +bool visited[MAX + 1]; + +int main () { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n, k; + cin >> n >> k; + + queue q; + q.push(n); + visited[n] = true; + arr[n] = 0; + + while (!q.empty()) { + int x = q.front(); + q.pop(); + + if (x == k) { + cout << arr[x]; + return 0; + } + + int dx[3] = {x - 1, x + 1, x * 2}; + + for (int nxt : dx) { + if (0 <= nxt && nxt <= MAX && !visited[nxt]) { + visited[nxt] = true; + arr[nxt] = arr[x] + 1; + q.push(nxt); + } + } + } +} \ No newline at end of file