From ff962a430927c38758d92b8ace20d3f25f0ce4ee Mon Sep 17 00:00:00 2001 From: sh0723 Date: Sat, 27 Jun 2026 10:49:56 +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=20resolve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ17071/BOJ17071_V2.cpp | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/week3/BOJ17071/BOJ17071_V2.cpp diff --git a/src/week3/BOJ17071/BOJ17071_V2.cpp b/src/week3/BOJ17071/BOJ17071_V2.cpp new file mode 100644 index 0000000..f4b5c27 --- /dev/null +++ b/src/week3/BOJ17071/BOJ17071_V2.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; +int bro, subin; +int visited[2][500001]; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(NULL); + + cin >> subin >> bro; + + queue q; + q.push(subin); + visited[0][subin] = 1; + int t = 0; + while(!q.empty()) { + int size = q.size(); + int bro_pos = t * (t + 1) / 2 + bro; + if (bro_pos > 500000) break; + if (visited[t%2][bro_pos]) { + cout << t; + return 0; + } + + while(size--) { + 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