From 9d59b7535bbaa18ac92b97cddabf0ecc40bd49ff Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 15 Jun 2026 18:55:21 +0900 Subject: [PATCH 1/2] =?UTF-8?q?12851=20:=20=EC=88=A8=EB=B0=94=EA=BC=AD?= =?UTF-8?q?=EC=A7=88=202=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ12851/BOJ12851_V1.cpp | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/week3/BOJ12851/BOJ12851_V1.cpp diff --git a/src/week3/BOJ12851/BOJ12851_V1.cpp b/src/week3/BOJ12851/BOJ12851_V1.cpp new file mode 100644 index 0000000..482e5b8 --- /dev/null +++ b/src/week3/BOJ12851/BOJ12851_V1.cpp @@ -0,0 +1,43 @@ +#include +using namespace std; +int brother, subin; +int ret = INT_MAX; +int ret_cnt; +int visited[100001]; +void solve(int idx, int level) { + if (idx > 100000 || idx < 0) { + return; + } + if (visited[idx]) return; + if (level > ret) return; + if (level == ret && idx == brother) { + ret_cnt++; + return; + } + if (idx == brother && level < ret) { + ret = level; + ret_cnt = 1; + return; + } + + visited[idx] = 1; + solve(idx-1, level+1); + solve(idx+1, level+1); + solve(idx*2, level+1); + visited[idx] = 0; +} +int main() { + + ios::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + + cin >> subin >> brother; + + solve(subin, 0); + + cout << ret << '\n' << ret_cnt << '\n'; + + + return 0; +} \ No newline at end of file From 6f7d8586ea0bbc373bec47aa3b29750eb1f353b2 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Thu, 18 Jun 2026 19:42:35 +0900 Subject: [PATCH 2/2] =?UTF-8?q?12851=20:=20=EC=88=A8=EB=B0=94=EA=BC=AD?= =?UTF-8?q?=EC=A7=88=20V2=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ12851/BOJ12851_V2.cpp | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/week3/BOJ12851/BOJ12851_V2.cpp diff --git a/src/week3/BOJ12851/BOJ12851_V2.cpp b/src/week3/BOJ12851/BOJ12851_V2.cpp new file mode 100644 index 0000000..9cb21e3 --- /dev/null +++ b/src/week3/BOJ12851/BOJ12851_V2.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; +int brother, subin; +int visited[100001]; +int cnt[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; + cnt[subin] = 1; + int now; + while(!q.empty()) { + now = q.front(); + q.pop(); + for (int next : {now-1, now+1, now *2}) { + if (0 <= next && next <= 100000) { + if (visited[next] == 0) { + q.push(next); + visited[next] = visited[now] + 1; + cnt[next] = cnt[now]; + } else if (visited[next] == visited[now] + 1) { + cnt[next] += cnt[now]; + } + + } + } + + } + + cout << visited[brother]-1 << '\n' << cnt[brother] << '\n'; + return 0; +} \ No newline at end of file