From 7d76cbc6a9637f81743f1adeeb86a3ca89da2e39 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Fri, 19 Jun 2026 20:04:38 +0900 Subject: [PATCH] =?UTF-8?q?13913=20:=20=EC=88=A8=EB=B0=94=EA=BC=AD?= =?UTF-8?q?=EC=A7=88=204=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ13913/BOJ13913_V1.cpp | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/week3/BOJ13913/BOJ13913_V1.cpp diff --git a/src/week3/BOJ13913/BOJ13913_V1.cpp b/src/week3/BOJ13913/BOJ13913_V1.cpp new file mode 100644 index 0000000..4f16eb5 --- /dev/null +++ b/src/week3/BOJ13913/BOJ13913_V1.cpp @@ -0,0 +1,48 @@ +#include +using namespace std; +stack ret; +int subin, brother; +int curr_val, next_val; +int visited[100001]; +int parent[100001]; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> subin >> brother; + queue q; + q.push(subin); + visited[subin] = 1; + while (!q.empty()) { + curr_val = q.front(); + q.pop(); + if (curr_val == brother) { + break; + } + for (int next : {curr_val + 1, curr_val - 1, curr_val * 2}) { + if (next < 0 || next > 100000) continue; + if (visited[next]) continue; + visited[next] = visited[curr_val] + 1; + parent[next] = curr_val; + q.push(next); + } + } + + cout << visited[brother]-1 << '\n'; + int cur = brother; + while(true) { + ret.push(cur); + if (cur == subin) break; + cur = parent[cur]; + } + + while(!ret.empty()) { + cout << ret.top() << ' '; + ret.pop(); + } + + + return 0; +} \ No newline at end of file