From b2afd231e730cd4b90babf787c68a3b53b8a60f8 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 22 Jun 2026 12:32:37 +0900 Subject: [PATCH] =?UTF-8?q?17071=20:=20=EC=88=A8=EB=B0=94=EA=BC=AD?= =?UTF-8?q?=EC=A7=88=205=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ17071/BOJ17071_V1.cpp | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/week3/BOJ17071/BOJ17071_V1.cpp diff --git a/src/week3/BOJ17071/BOJ17071_V1.cpp b/src/week3/BOJ17071/BOJ17071_V1.cpp new file mode 100644 index 0000000..1842ad0 --- /dev/null +++ b/src/week3/BOJ17071/BOJ17071_V1.cpp @@ -0,0 +1,48 @@ +#include +using namespace std; +int visited[2][500001]; +int bro, subin; +int main() { + + ios_base::sync_with_stdio(false); + cout.tie(NULL); + cin.tie(NULL); + + cin >> subin >> bro; + + if (subin == bro) { + cout << 0; + return 0; + } + + queue q; + q.push(subin); + visited[0][subin] = 1; + int t=0; + while(!q.empty()) { + int qsize = q.size(); + int brother_pos = t*(t+1)/2 + bro; + if (brother_pos > 500000) + break; + if (visited[t%2][brother_pos]) { + cout << t; + return 0; + } + while(qsize--) { + int curr = q.front(); + q.pop(); + + for (int next : {curr-1, curr+1, curr*2}) { + if (next < 0 || next > 500000) continue; + if (visited[(t+1)%2][next]) continue; + visited[(t+1)%2][next] = 1; + q.push(next); + } + } + t++; + } + + cout << -1; + + return 0; +} \ No newline at end of file